Plot two graphs in same plot in R

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

    You could use the ggplotly() function from the plotly package to turn any of the gggplot2 examples here into an interactive plot, but I think this sort of plot is better without ggplot2:

    # call Plotly and enter username and key
    library(plotly)
    x  <- seq(-2, 2, 0.05)
    y1 <- pnorm(x)
    y2 <- pnorm(x, 1, 1)
    
    plot_ly(x = x) %>%
      add_lines(y = y1, color = I("red"), name = "Red") %>%
      add_lines(y = y2, color = I("green"), name = "Green")
    

提交回复
热议问题