Overlay graphic on R

Question:

how can I overlay two or more graphs without the axes boundaries also appearing overlaid on 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')

It is also possible to 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'))
Scroll to Top