[R] draw two plots on a single panel

From: Nguyen Dinh Nguyen <n.nguyen_at_garvan.org.au>
Date: Thu, 10 May 2007 08:29:45 +1000

Hi Pat,
Certainly you can
But you need to provide more details, will advise closely In general, first you plot the “frame” without plotting like this

plot(range(data1$x1,data2$x2), range(data1$y1,data2$y2), type=’n’) # means just plotting a frame with xaxis ranges from x1-x2 and y from y1-y2, but no plotting

then depends on your data type (i.e. line or scatter or blah blah) then you have specific command for them
Give you here an example for reference:

# Two scatter plots in the same graph:

data1 <- data.frame(x1=rnorm(100,70,7), y1=rnorm(100,35,5)) data2 <- data.frame(x2=rnorm(100,78,8), y2=rnorm(100,40,5)) plot(range(data1$x1,data2$x2), range(data1$y1,data2$y2), type=’n’) points(data1$x1,data1$y1,pch=17, col=’blue’) points(data2$x2,data2$y2,pch=16, col=’red’)


Message: 82
Date: Tue, 8 May 2007 16:49:47 -0700 (PDT) From: "Patrick Wang" <pwang_at_berkeley.edu> Subject: [R] draw two plots on a single panel To: r-help_at_stat.math.ethz.ch

        <52196.> Content-Type: text/plain;charset=iso-8859-1


I have 2 dataset,


but it comes as two graphs, can I draw both on a single panel so I can compare them?


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 and provide commented, minimal, self-contained, reproducible code. Received on Wed 09 May 2007 - 22:34:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 May 2007 - 23:32:03 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.