Plotting multiple curves same graph and same scale

Viewed 164445

This is a follow-up of this question.

I wanted to plot multiple curves on the same graph but so that my new curves respect the same y-axis scale generated by the first curve.

Notice the following example:

y1 <- c(100, 200, 300, 400, 500)
y2 <- c(1, 2, 3, 4, 5)
x <- c(1, 2, 3, 4, 5)

# first plot
plot(x, y1)

# second plot
par(new = TRUE)
plot(x, y2, axes = FALSE, xlab = "", ylab = "")

That actually plots both sets of values on the same coordinates of the graph (because I'm hiding the new y-axis that would be created with the second plot).

My question then is how to maintain the same y-axis scale when plotting the second graph.

5 Answers
Related