Add a line from another data.frame to qplot

前端 未结 1 1879
忘掉有多难
忘掉有多难 2021-02-04 12:00

Is it possible to add a line (such as an additional time series) to an already existing plot? I know how to add horizontal or vertical lines, but how can I add from other data.

1条回答
  •  遇见更好的自我
    2021-02-04 12:17

    by using ggplot() instead of qplot(), you can have more flexibility. here is a minimal example using two datasets:

    d1 <- data.frame(x1=rep(1:10,3), y1=rnorm(10*3), g1=gl(3,10,labels=letters[1:3]))
    d2 <- data.frame(x2=rep(1:10,3), y2=rnorm(10*3), g2=gl(3,10, labels=letters[4:6]))
    
    ggplot() + 
      geom_line(aes(x1, y1, colour=g1), d1) +  
      geom_line(aes(x2, y2, colour=g2), d2)
    

    0 讨论(0)
提交回复
热议问题