Dear R users, If I have to combine plots which have the same independent and dependent variables in one graph. Which command should I use? Any example? Can I use "panel"? Your help will be deeply appreciated. Thanks! -Vivien Chen- [[alternative HTML version deleted]]
On 11/16/05 8:48 AM, "Vivien W. Chen" <wxc203 at psu.edu> wrote:> Dear R users, > > If I have to combine plots which have the same independent and dependent > variables in one graph. Which command should I use? Any example? Can I use > "panel"?Viven, plot(x1,y1) par(new=TRUE) plot(x2,y2) You may have to use xlim and ylim to get the plots to match axes. Alternatively, plot(x1,y1) points(x2,y2) # or use lines, or whatnot Sean
You can also look at xyplot in the lattice package. You will have to set up your data slightly differently than for the standard graphics package, but it may well be worth learning to do so. The lattice package has enormous flexibility for combining multiple sets of data in one panel or plotting them in separate panels. Hope this helps, Matt -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Vivien W. Chen Sent: Wednesday, November 16, 2005 8:49 AM To: r-help at stat.math.ethz.ch Subject: [R] Combine related plots Dear R users, If I have to combine plots which have the same independent and dependent variables in one graph. Which command should I use? Any example? Can I use "panel"? Your help will be deeply appreciated. Thanks! -Vivien Chen- [[alternative HTML version deleted]] ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On 11/17/05 8:05 AM, "Vivien W. Chen" <wxc203 at psu.edu> wrote:> Sean, > > Thanks! > It works! > I have another extended question: how to label the two lines in the graph? > I tried many ways, including text, label, list, etc., just cannot give a > very effective way to do.If I were you, I would play with the "legend" command. It places a legend on the plot; you can have the two different line styles that you used to draw the original lines labeled with the names. See the help for legend and just play with it a bit. x2 <- rnorm(100) + 1:100 x1 <- rnorm(100) + 1:100 plot(x1,type='l',col='red') lines(x2,col='green') legend(x=5,y=90,legend=c('line1','line2'),col=c('red','green'),lty=1) Glad it worked for you. Sean