[R] plotting multiple lines on single graph ggplot2

Ben Bolker bbolker at gmail.com
Mon Nov 28 17:31:33 CET 2011


John Kane <jrkrideau <at> yahoo.ca> writes:

> 
> There are probably lots of better aproaches but this seems to work.
>   I just combined the lines into one vector
> and assighed a dummy variable to mark the diffferent lines
> 
> ibrary(ggplot2)
> mydata <- data.frame(xrange <- c(100, 200, 300, 400, 500, 600, 
>         700, 800, 900, 1000),
>         yrange = c( 1.1, 1.2, 1.3, 1.4, 1.5, 1.5, 1.7, 1.9, 2.0, 2.4),
>         mark = c(rep("a",5), rep("b", 5)))
> 
> p <- ggplot(mydata, aes( xrange, yrange, colour= mark)) 
> 
> p <- p + geom_line()
> 
> p

  Yes, or qplot(xrange,yrange,colour=mark,data="mydata")

This was cross-posted to stack overflow: please don't crosspost.
(I didn't understand the question until just now, it was simpler
than I thought -- I thought the OP wanted *four* lines on the final
plot (not "I have four lines of data").



More information about the R-help mailing list