Question :
How can I superimpose two or more graphs without the axis limits also overlapping in the figure?
a = rnorm(1000)
b = runif(1000)
plot(a, type = "l")
par(new = T)
plot(b, type = "l", col = "blue", xlab = "", ylab = "")
#os eixos de y ficam sobrepostos
Answer :
If your goal is the same as the example, one solution is to use matplot()
a = rnorm(1000)
b = runif(1000)
matplot(cbind(a, b), type = 'l')
You can also do with ggplot
:
library(ggplot2)
ggplot(data = data.frame(a = a, b = b, x = 1:1000)) + geom_line(aes(x = x, y = a, colour = 'a')) + geom_line(aes(x = x, y = b, colour = 'b'))
Instead of drawing the two graphs, you can draw the first graph, and then add only the lines of the second series. This will give you both “overlapping” graphics
a = rnorm(1000)
b = runif(1000)
plot(a, type = "l")
lines(b, col = "blue")