我正在使用模型来预测某些数字。我的预测还包括每个数字的置信区间。我需要在同一个图上绘制实际数字+预测数字及其分位数值。这是一个简单的例子:
actualVals = c(12,20,15,30)
lowQuantiles = c(19,15,12,18)
midQuantiles = c(22,22,17,25)
highQuantiles = c(30,25,25,30)
答案 0 :(得分:1)
您可以使用geom_errorbar
,其他人可以在?geom_errorbar
看到。我根据您的变量dat
创建了一个data.frame,并添加了dat$x <- 1:4
。
ggplot(dat) +
geom_errorbar(aes(x, y=midQuantiles, ymax=highQuantiles, ymin=lowQuantiles, width=0.2), lwd=2, color="blue") +
geom_point(aes(x, midQuantiles), cex=4, shape=22, fill="grey", color="black") +
geom_line(aes(x, actualVals), color="maroon", lwd=2) +
geom_point(aes(x, actualVals), shape=21, cex=4, fill="white", color='maroon') +
ylim(0, 30) +
theme_bw()