R 水平和垂直误差条上的凸包

R 水平和垂直误差条上的凸包,r,ggplot2,convex-hull,R,Ggplot2,Convex Hull,我有一个带有平均值和水平和垂直误差条的ggplot,我想添加一个包含所有误差条的凸包-如下所示: 我试过使用ggpubr中的stat\u chull,但不确定当每个点的错误条出现xmin、xmax、ymin时,如何指定美学效果。下面是我如何对绘图进行编码,以X和Y表示的stat\u chullaes为例-我知道这是不正确的,但我认为我的思路是正确的 ggplot()+ geom_point(data = df, aes(MeanX,MeanY)) + geom_errorbar(dat

我有一个带有平均值和水平和垂直误差条的ggplot,我想添加一个包含所有误差条的凸包-如下所示:

我试过使用
ggpubr
中的
stat\u chull
,但不确定当每个点的错误条出现
xmin
xmax
ymin
时,如何指定美学效果。下面是我如何对绘图进行编码,以X和Y表示的
stat\u chull
aes
为例-我知道这是不正确的,但我认为我的思路是正确的

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_多边形,结果得到了垃圾

以下是有关数据的示例:

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")

df以下内容对您有用吗

library(dplyr)

df %>%
  mutate(ymin = MeanY - SdY,
         ymax = MeanY + SdY,
         xmin = MeanX - SdX,
         xmax = MeanX + SdX) %>%
  ggplot(aes(x = MeanX, y = MeanY))+
  geom_point() +
  geom_errorbar(aes(ymin = ymin, ymax = ymax),
                width = 0)+
  geom_errorbarh(aes(xmin = xmin, xmax = xmax),
                 height = 0)+
  stat_chull(data = . %>%
               summarise(x = c(MeanX, MeanX, MeanX, xmin, xmax),
                         y = c(MeanY, ymin, ymax, MeanY, MeanY)),
             aes(x = x, y = y),
             geom = "polygon", colour = "black", fill = NA)+
  theme_classic()

谢谢@Z.Lin。这不是我期望的解决方法,但效果很好!