On 10 January 2011 16:38, Santosh Srinivas <santosh.srini...@gmail.com> wrote: > Thanks Baptiste that works but keen to know if there are other ways. > > I'm new to ggplot .. just wondering if there is no easy way to overlay the > new data i.e vol over my Close chart?
Sure, ggplot2 has the concept of layers, qplot(Date, Close, data=dat,geom="line") + geom_line(aes(Date, vol), colour="red") HTH, baptiste > > > -----Original Message----- > From: baptiste auguie [mailto:baptiste.aug...@googlemail.com] > Sent: 10 January 2011 18:59 > To: Santosh Srinivas > Cc: r-help@r-project.org > Subject: Re: [R] Basic ggplot question > > Hi, > > Try this, > > m = melt(dat, id="Date") > head(m) > > qplot(Date, value, data=m, colour=variable, geom="line") > > ggplot(m) + facet_grid(variable~., scales="free_y") + > geom_path(aes(Date, value)) > > > HTH, > > baptiste > > On 10 January 2011 14:12, Santosh Srinivas <santosh.srini...@gmail.com> > wrote: >> Hello R-Group, >> >> I am trying plotting simple time-series with ggplot2 because the output >> looks better and I've heard its richer in features. >> >> I have the following dataset. >>> dput(dat) >> structure(list(Date = structure(c(14970, 14971, 14972, 14973, >> 14974, 14977, 14978, 14979, 14980, 14981), class = "Date"), Close = >> c(5998.1, >> 5996, 6060.35, 6101.85, 6134.5, 6157.6, 6146.35, 6079.8, 6048.25, >> 5904.6), vol = c(0.154535414667409, 0.151830297402932, 0.140309395040681, >> 0.136253183394409, 0.137108091041075, 0.137109537791588, > 0.137664093371524, >> 0.141313700592413, 0.123866294210121, 0.139356235990631)), .Names = >> c("Date", >> "Close", "vol"), row.names = c("4905", "4906", "4907", "4908", >> "4909", "4910", "4911", "4912", "4913", "4914"), class = "data.frame") >> >> I can get one plot using: >> qplot(Date, Close, data=dat,geom="line") >> >> How can I plot both Close and vol on the same chart? >> >> Been breaking my head on this ... thanks for your help in advance. >> >> Regards, >> S >> >> ______________________________________________ >> R-help@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. >> > > ______________________________________________ R-help@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.