Change the overlaying order of lines in ggplot

前端 未结 2 2002
走了就别回头了
走了就别回头了 2021-01-17 12:13

Suppose I have this plot:

library(ggplot2)
pl_data <- data.frame(x = rep(c(1, 2), times = 3), y = c(0, 1, 1, 0, .7, .7), col = rep(c(\"r\", \"b\", \"g\"),         


        
2条回答
  •  别那么骄傲
    2021-01-17 12:47

    library(ggplot2)
    df <- data.frame(
      x = rep(c(1, 2), times = 3), 
      y = c(0, 1, 1, 0, .7, .7), 
      col = rep(c("r", "b", "g"), each = 2))
    
    ggplot() + 
      geom_line(data = df[3:4,], aes(x = x, y = y), color = 'blue', size = 3) +
      geom_line(data = df[5:6,], aes(x = x, y = y), color = 'green', size = 3) +
      geom_line(data = df[1:2,], aes(x = x, y = y), color = 'red', size = 3)
    

提交回复
热议问题