[R] Combine related plots

Sean Davis sdavis2 at mail.nih.gov
Thu Nov 17 14:27:02 CET 2005


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




More information about the R-help mailing list