[R] How to plot multiple datasets

David L Carlson dcarlson at tamu.edu
Thu Jan 3 20:06:26 CET 2013


Or

> matplot(x, cbind(y1, y2, y3), ylab="y", col=c("black", "red",
   "blue"), pch=1) # symbols
> matplot(x, cbind(y1, y2, y3), ylab="y", col=c("black", "red",
  "blue"), type="l") # lines

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Rui Barradas
> Sent: Thursday, January 03, 2013 12:54 PM
> To: Bruce Kindseth
> Cc: r-help at r-project.org
> Subject: Re: [R] How to plot multiple datasets
> 
> Hello,
> 
> You shuld provide a data example, but see if the following is what you
> are looking for.
> 
> x <- 1:10
> y1 <- rnorm(10)
> y2 <- rnorm(10)
> y3 <- rnorm(10)
> 
> # One way
> plot(x, y1, ylim = range(c(y1, y2, y3)))
> points(x, y2, col = "red")
> points(x, y3, col = "blue")
> 
> # Another way
> plot(x, y1, ylim = range(c(y1, y2, y3)), type = "l")
> lines(x, y2, col = "red")
> lines(x, y3, col = "blue")
> 
> 
> Hope this helps,
> 
> Rui Barradas
> Em 03-01-2013 16:39, Bruce Kindseth escreveu:
> > Good Morning,
> >
> > I have 3 sets of data, all with the same horizontal axis but with
> varying
> > vertical input.  I want to plot all 3 sets on one x-y plot.  I can
> get 3
> > linear regression plots and 3 polynomial regression plots on the same
> chart
> > but I have not been able to get more than one set of input data on
> the same
> > chart.  Can you help me?
> >
> > Thank you for all that you do to provide R to the public.
> >
> > Bruce Kindseth
> >
> > Narragansett, RI
> >
> >
> > 	[[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at 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 at 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.




More information about the R-help mailing list