我知道如何使用常规数值制作直方图,但我希望能够执行类似以下的操作:
我想知道如何在t-1
的水平轴上为值t-2
,t-3
和ggplot2
制作直方图。
df <- data.frame(trt = c("t-3", "t-2", "t-1", "t"), outcome = c(3, 6, 9, 5))
ggplot(df, aes(trt, outcome)) +
geom_col()
答案 0 :(得分:0)
对于那些感兴趣的人,我得到了如下所需的结果:
df <- data.frame(trt = factor(c("t-3", "t-2", "t-1", "t"),
levels = c("t-3", "t-2", "t-1", "t")), outcome = c(9, 3, 7, 4))
myColors <- c("red","red","red", "blue")
u <- (9+3+7)/3
ggplot(df, aes(trt, outcome)) + geom_col(colour = "black",
fill = myColors)+geom_hline(yintercept=u, linetype="dashed",
color = "black") + xlab("Week") + ylab("Search Volume") +
theme_minimal()+theme(axis.text.y=element_blank(),
axis.ticks.y=element_blank())
最终看起来像这样;