【发布时间】:2021-01-22 02:58:53
【问题描述】:
我有一个带有均值和水平和垂直误差线的 ggplot,我想添加一个包含所有误差线的凸包 - 像这样:
我尝试过使用ggpubr 中的stat_chull,但我不确定如何在每个点的误差条有xmin、xmax、ymin 和ymax 时指定美学。下面是我如何编码指定 stat_chull aes 作为 X 和 Y 表示的情节作为示例 - 我知道这是不正确的,但我认为我在正确的轨道上?
ggplot()+
geom_point(data = df, aes(MeanX,MeanY)) +
geom_errorbar(data = df,
mapping = aes(x = MeanX,
ymin = MeanY - SdY,
ymax = MeanY + SdY),
width = 0, inherit.aes = FALSE)+
geom_errorbarh(data = df,
mapping = aes(y = MeanY,
xmin = MeanX - SdX,
xmax = MeanX + SdX),
height = 0, inherit.aes = FALSE)+
stat_chull(data = df, aes(MeanX,MeanY))+
theme_classic()
这给出了以下情节:
我也试过 geom_polygon 并得到了垃圾。
这是一个数据:
df<-structure(list(Source = structure(1:5, .Label = c("A", "B", "C", "D",
"E"), class = "factor"), MeanX = c(-18.7066666666667,
-15.8769230769231, -16.8620689655172, -15.72, -17.4333333333333
), SdX = c(1.61072554509115, 0.409201849758959, 1.04811067886951,
0.74057035077327, 1.15902257671425), MeanY = c(9.93666666666667,
14.3230769230769, 9.22758620689655, 11.1, 13.7333333333333),
SdY = c(1.03005970142791, 0.539116085686704, 0.504990221704281,
0.757187779440037, 1.05039675043925)), row.names = c(NA,
-5L), class = "data.frame")
非常感谢任何帮助!
【问题讨论】:
标签: r ggplot2 convex-hull