Skip to content

Plotting points from two vectors onto the same graph

1 message · Marc Schwartz

#
On Thu, 2005-01-20 at 20:51 -0500, K Fernandes wrote:
First, 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