Plot two graphs in same plot in R

前端 未结 16 852
感情败类
感情败类 2020-11-22 03:37

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\")         


        
16条回答
  •  自闭症患者
    2020-11-22 04:14

    You can also use par and plot on the same graph but different axis. Something as follows:

    plot( x, y1, type="l", col="red" )
    par(new=TRUE)
    plot( x, y2, type="l", col="green" )
    

    If you read in detail about par in R, you will be able to generate really interesting graphs. Another book to look at is Paul Murrel's R Graphics.

提交回复
热议问题