path producing continuing connection

20 views
Skip to first unread message

Troels Ring

unread,
May 1, 2016, 5:20:29 AM5/1/16
to ggplot2
dear friends - I have a data frame, attached as all.dat - 
ALL <- dget("all.dat")
PP <- ggplot(ALL,aes(x=SID,y=pH))
FF <- PP +    geom_path(data=ALL,aes(X=SID,y=pH,colour=Albcol,lty=Pclass))
FF + facet_wrap(~PCO2class,ncol=3)

works pretty well but the lines continues - what I want is in correspondence with
for (i in 1:length(PCO2)) lines(ALL$SID[ALL$PCO2==PCO2[i]],ALL$pH[ALL$PCO2==PCO2[i]],col=p[i])
in ordinary plots - 

If I use geom_line the continuation is lost but there are steps. 

How to proceed

All best
Troels
all.dat

Brian

unread,
May 1, 2016, 8:17:56 AM5/1/16
to Troels Ring, ggplot2
Hi Troels,

thank you for the nice code and data.

It appears that your data has these steps as you mentioned. Reordering
the data based on pH changes that slightly, but not much. geom_path
obscures this. Based on what i think you want to do, you need to use
geom_line.

library(ggplot2)
ALL <- dget("all.dat")

## PP <- ggplot(ALL[order(ALL$pH),]) +
PP <- ggplot(ALL) +
geom_line(aes(x = SID, y = pH, colour = Albcol, linetype = Pclass)) +
facet_wrap(~PCO2class, ncol=3)
PP

I think you will have to change the data so that geom_line works, if I
understand you correctly.

Best
Brian
Message has been deleted

ggll

unread,
May 13, 2016, 9:21:30 PM5/13/16
to ggp...@googlegroups.com
If I understand your question, you need to map PCO2 to the
group aesthetics. In practice, add group=PCO2 in aes().
This will produce several paths, one for each level of PCO2.

Cheers,

Matteo
Reply all
Reply to author
Forward
0 new messages