这是我的数据框架,该数据帧具有模型构造后的自举过程的预测概率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上限和下限:
我尝试过的是
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()
但是背景没有颜色。仅用于Pred的箱线图,没有任何背景色:
我将不胜感激!