[R] Plotting Multiple lines on one plot

0 views
Skip to first unread message

R_Learner

unread,
Jul 22, 2008, 7:05:00 PM7/22/08
to r-h...@r-project.org

Hi,
I'm trying to plot multiple lines on one plot. I have a data frame raw,
and i want to plot raw$date on the x-axis and raw$theta, raw$vega,
raw$delta, and a few others on the y-axis, with a legend. However, I'm not
sure what the scale of those data sets are, and I don't know which one will
have the largest scale. How can I plot this? I've tried ggplot (qplot), but
it doesn't seem to be capable of multiple lines.

Thanks!
--
View this message in context: http://www.nabble.com/Plotting-Multiple-lines-on-one-plot-tp18600665p18600665.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-h...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

RichardP

unread,
Jul 22, 2008, 8:16:10 PM7/22/08
to r-h...@r-project.org

You can set the range for each axis on your plot using the ylim and xlim
parameters (use help to see how to implement them). You can find the range
or minimum and maximum for each variable (or a number of variables at once)
using the min and max commands.

If you're ranges vary too much though it will be hard to visualise all the
data on the same axis.


R_Learner wrote:
>
> Hi,
> I'm trying to plot multiple lines on one plot. I have a data frame raw,
> and i want to plot raw$date on the x-axis and raw$theta, raw$vega,
> raw$delta, and a few others on the y-axis, with a legend. However, I'm not
> sure what the scale of those data sets are, and I don't know which one
> will have the largest scale. How can I plot this? I've tried ggplot
> (qplot), but it doesn't seem to be capable of multiple lines.
>
> Thanks!
>

--
View this message in context: http://www.nabble.com/Plotting-Multiple-lines-on-one-plot-tp18600665p18601515.html

hadley wickham

unread,
Jul 23, 2008, 10:09:49 AM7/23/08
to R_Learner, r-h...@r-project.org
The easiest way to do with this ggplot2 is to melt your data first:

dfm <- melt(df, id = "date", measure = c("theta","vega","delta"))
qplot(date, value, data=dfm, geom="line", colour = variable)

Hadley

--
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages