plotting many lines - simplification

42 views
Skip to first unread message

Troels Ring

unread,
Apr 12, 2015, 2:53:57 AM4/12/15
to ggp...@googlegroups.com
Hi friends - I managed to simplify my question very much: I have a plot which works just fine, MPH and fpH each 76, predicts is a data.frame length 1000 of x and y

pp <- ggplot(FH0,aes(x=MPH,y= fpH))+geom_line(linetype=1,size=3,colour="blue")+
ylab("Fitted pH")+xlab("Measured pH")+xlim(c(6.9,7.7)) +ylim(c(6.9,7.7))
ppp <- pp + theme_bw()+ geom_line(data=predicts,size=3,col="red") 
ppp

and then I have the desire to add a line specified in the data.frame slines
> slines
       x        y
1  7.220 7.349371
2  7.290 7.413105
3  7.290 7.413105
4  7.300 7.422209
5  7.315 7.435867
6  7.320 7.440419
7  7.400 7.513257
8  7.410 7.522362
9  7.430 7.540571
10 7.440 7.549676

when I do naively
ppp + geom_line(data=slines,size=0.1)

I get the message
error: Aesthetics must either be length one, or the same length as the dataProblems:fpH - what goes wrong here?


Doug Mitarotonda

unread,
Apr 12, 2015, 2:19:29 PM4/12/15
to Troels Ring, ggp...@googlegroups.com
It would be easier to help if you had a fully working example, but my guess is that you would need to do `ppp + geom_line(aes(x = x, y = y), data = slines, size = 0.1)` because you are no longer using the “default” aesthetics you put in the ggplot call.

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Troels Ring

unread,
Apr 12, 2015, 3:27:09 PM4/12/15
to Doug Mitarotonda, ggp...@googlegroups.com
I'm sorry, but the start is complicated, so I thought it might work to translate the problem to the simpler, i.e. having one plot which is as wanted - and then just adding this simple line as specified with slines - and your suggestion did just that - thanks a lot!!!
Troels
You received this message because you are subscribed to a topic in the Google Groups "ggplot2" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ggplot2/0JVrv6g3SVk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ggplot2+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages