Plot two graphs in same plot in R

前端 未结 16 827
感情败类
感情败类 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:19

    we can also use lattice library

    library(lattice)
    x <- seq(-2,2,0.05)
    y1 <- pnorm(x)
    y2 <- pnorm(x,1,1)
    xyplot(y1 + y2 ~ x, ylab = "y1 and y2", type = "l", auto.key = list(points = FALSE,lines = TRUE))
    

    For specific colors

    xyplot(y1 + y2 ~ x,ylab = "y1 and y2", type = "l", auto.key = list(points = F,lines = T), par.settings = list(superpose.line = list(col = c("red","green"))))
    

提交回复
热议问题