Mulholland, Tom
2005-Jan-21 02:31 UTC
[R] Plotting points from two vectors onto the same graph
?points has this example plot(-4:4, -4:4, type = "n")# setting up coord. system points(rnorm(200), rnorm(200), col = "red") points(rnorm(100)/2, rnorm(100)/2, col = "blue", cex = 1.5) In general you might want to check out the keyword section of the help, in particular the Graphics section which has an entry called aplot for ways to add to existing plots. Tom> -----Original Message----- > From: K Fernandes [mailto:kafernan at uwaterloo.ca] > Sent: Friday, 21 January 2005 9:51 AM > To: r-help at stat.math.ethz.ch > Subject: [R] Plotting points from two vectors onto the same graph > > > Hello, > > I have three vectors defined as follows: > > > x<-c(10,20,30,40,50) > > y1<-c(154,143,147,140,148) > > y2<-c(178,178,171,188,180) > > I would like to plot y1 vs x and y2 vs x on the same graph. > How might I do > this? I have looked through a help file on plots but could > not find the > answer to plotting multiple plots on the same graph. > > Thank you for your help, > K > > ______________________________________________ > 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 >
Marc Schwartz
2005-Jan-21 02:47 UTC
[R] Plotting points from two vectors onto the same graph
On Thu, 2005-01-20 at 20:51 -0500, K Fernandes wrote:> Hello, > > I have three vectors defined as follows: > > > x<-c(10,20,30,40,50) > > y1<-c(154,143,147,140,148) > > y2<-c(178,178,171,188,180) > > I would like to plot y1 vs x and y2 vs x on the same graph. How might I do > this? I have looked through a help file on plots but could not find the > answer to plotting multiple plots on the same graph. > > Thank you for your help, > KFirst, when posting a new query, please do not do so by replying to an existing post. Your post is now listed in the archive linked to an entirely different thread. The easiest way to do this is to use the matplot() function: x <- c(10,20,30,40,50) y1 <- c(154,143,147,140,148) y2 <- c(178,178,171,188,180) # now do the plot. cbind() the two sets of y values # and the x values with be cycled for each matplot(x, cbind(y1, y2), col = c("red", "blue")) See ?matplot for more information. HTH, Marc Schwartz