在这个情节中
df <- data.frame(factor = as.factor(c(rep("A",3), rep("B",3))), Treatment = c(rep(c("A","B","C"),2)), values=runif(6,0,1))
ggplot(df, aes(Treatment, values))+
geom_bar(stat="identity", position="dodge") +
facet_wrap(~factor)
如何使用给定治疗级别的geom_hline
(例如“A”)向每个方面添加yintercept
+geom_hline(data=df, aes(yintercept= df[df$Treatment=="A",]))
不起作用:
错误:美学必须是长度1或与数据(6)相同: y截距
答案 0 :(得分:2)
library(tidyverse)
df <- data.frame(factor = as.factor(c(rep("A",3), rep("B",3))), Treatment = c(rep(c("A","B","C"),2)), values=runif(6,0,1))
ggplot(df, aes(Treatment, values))+
geom_bar(stat="identity", position="dodge") +
facet_wrap(~factor) +
geom_hline(data = df %>% filter(Treatment == "A"), aes(yintercept = values))
由reprex package(v0.2.0)创建于2018-03-23。