【发布时间】:2017-07-03 15:39:47
【问题描述】:
我在使用带有 ggplot 的多边形时遇到问题。我绘制了一些模型预测和观察结果(平均值和置信水平),并且我想为观察的置信水平绘制一个多边形。这是我的数据
Mat_ic_mu=matrix(c(-3.347582, -3.297287, -3.333237, -3.206484, -3.313200,
-3.313200,-3.313200,-3.313200,-3.355346, -3.315213, -3.354656, -3.252734,
-3.328607, -3.328607, -3.328607, -3.328607,-3.363109, -3.333138,
-3.376076, -3.298983, -3.344014, -3.344014, -3.344014,
-3.344014),ncol=3,nrow=8)
modelName=c("model 1","model 2","model 3","model 0")
type=rep(c("Pred modèle", "Obs"), each = 4)
boxdata=data.frame(Mat_ic_mu,modelName,type)
colnames(boxdata)=c("icp","pred","icm","model","type")
ggplot(boxdata, aes(x = model, y = pred, ymax = icp, ymin = icm,
group = type, colour = type, shape = type)) +
geom_errorbar(width=0.20) +
geom_point() +
scale_shape_manual(name="legend",values=c(19, 4)) +
scale_color_manual(name="legend",values = c("orange","deepskyblue")) +
xlab("modèles") +
ylab("intervalle de confiance")+
ggtitle(paste("Intervalle de confiance en ",end_year+1," pour ",Pays_a_predire," âge " , age_bp+start_age-1,sep=""))
我想要的是为我的 Obs 添加polygon,但这么久以来我都想不出一种将geom_polygon 添加到我的代码中的方法。
结果图如下:
但我真正想要的是更像这样的东西:
【问题讨论】:
-
我建议使用
geom_ribbon和geom_line。 -
你能推荐一种使用它们的方法吗?主要问题是我不知道该为数据和 aes 提供什么参数
-
您的示例数据给了我一个完全不同的情节。 (观察和预测是一样的)
-
我已经修改了数据,请您考虑更新一下,现在应该可以了。