How to add different lines for facets

前端 未结 1 1702
既然无缘
既然无缘 2020-11-27 16:03

I have data where I look at the difference in growth between a monoculture and a mixed culture for two different species. Additionally, I made a graph to make my data clear.

相关标签:
1条回答
  • 2020-11-27 16:25

    Make sure that the variable species is identical in both datasets. If it a factor in one on them, then it must be a factor in the other too

    library(ggplot2)
    dummy1 <- expand.grid(X = factor(c("A", "B")), Y = rnorm(10))
    dummy1$D <- rnorm(nrow(dummy1))
    dummy2 <- data.frame(X = c("A", "B"), Z = c(1, 0))
    ggplot(dummy1, aes(x = D, y = Y)) + geom_point() + facet_grid(~X) + 
        geom_hline(data = dummy2, aes(yintercept = Z))
    

    enter image description here

    dummy2$X <- factor(dummy2$X)
    ggplot(dummy1, aes(x = D, y = Y)) + geom_point() + facet_grid(~X) + 
        geom_hline(data = dummy2, aes(yintercept = Z))
    

    enter image description here

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