Plot two graphs in same plot in R

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

    You can also create your plot using ggvis:

    library(ggvis)
    
    x  <- seq(-2, 2, 0.05)
    y1 <- pnorm(x)
    y2 <- pnorm(x,1,1)
    df <- data.frame(x, y1, y2)
    
    df %>%
      ggvis(~x, ~y1, stroke := 'red') %>%
      layer_paths() %>%
      layer_paths(data = df, x = ~x, y = ~y2, stroke := 'blue')
    

    This will create the following plot:

提交回复
热议问题