我知道如何用规则的数值制作直方图,但是我希望能够做一些类似于以下内容的事情:

我想知道如何为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()发布于 2018-05-27 15:10:06
对于那些感兴趣的人,我得到了以下预期的结果:
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())最后看起来像这样;

https://stackoverflow.com/questions/50552828
复制相似问题