Monday, February 4, 2019

Plot two graphs in same plot in R



I would like to plot y1 and y2 in the same plot.



x  <- seq(-2, 2, 0.05)
y1 <- pnorm(x)

y2 <- pnorm(x, 1, 1)
plot(x, y1, type = "l", col = "red")
plot(x, y2, type = "l", col = "green")


But when I do it like this, they are not plotted in the same plot together.



In Matlab one can do hold on, but does anyone know how to do this in R?


Answer



lines() or points() will add to the existing graph, but will not create a new window. So you'd need to do




plot(x,y1,type="l",col="red")
lines(x,y2,col="green")

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...