这是我的数据框架,在构建模型后,从引导过程中预测概率 Pred
:
require(ggplot2)
Position <- rep(c("B", "A", "Stg", "Str"),3)
Week <- c(rep("1",4), rep("2",4), rep("3",4))
LC <- c(1.09E-02,1.40E-02,1.20E-02,2.86E-02,1.27E-05,1.26E-07,
5.47E-02,1.34E-01,1.21E-02,8.51E-03,2.27E-02,2.61E-02)
Pred <- c(0.057243157,0.044744656,0.068085039,0.120633045,
0.002791358,0.005735141,0.230200726,0.38286196,
0.044698511,0.042201468,0.120200443,0.125982336)
UC <- c(3.06E-02,3.82E-02,4.05E-02,7.50E-02,2.86E-03,
1.94E-05,1.59E-01,2.83E-01,2.83E-02,2.91E-02,
7.35E-02,7.59E-02)
df <- data.frame(Position, Week, LC, Pred, UC)
Position
和 Week
是其余数字的因子 . 我想在x轴上显示 Position
,在框图中显示y轴上的 Pred
. LC
和 UC
是置信区间的下限和上限 . 我的目的是在背景中将限制显示为彩色区域,就像本例中的代码一样
ggplot(df, aes(x = Week, y = Pred, fill = Position)) +
geom_ribbon(aes(ymin = LC, ymax = UC, fill = Position), alpha = .15) +
geom_boxplot(aes(colour = Position), size = 2) +
ylim(c(0, 0.7))
上部和下部CI限制的彩色背景的Boxplot:
我尝试的是
ggplot(df, aes(x = Position, y = Pred, fill = Position)) +
geom_ribbon(data=pred,aes(ymin = LC, ymax = UC, fill = Position),
alpha = .15) +
geom_boxplot(aes(colour = Position), size = 2, colour="black") +
stat_summary(fun.y=mean, geom = "point", size = 1.5) + theme_bw()
但背景中没有颜色 . 只有没有任何背景颜色的Predp的Boxplot:
我很感激任何建议!