Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用镶嵌面网格时在ggplot2中指定自定义错误栏_R_Ggplot2 - Fatal编程技术网

R 使用镶嵌面网格时在ggplot2中指定自定义错误栏

R 使用镶嵌面网格时在ggplot2中指定自定义错误栏,r,ggplot2,R,Ggplot2,我使用stat\u summary从数据中创建了多个条形图。但是,我想手动指定错误条的限制(而不是使用mean\u cl\u boot)。如何对使用facet\u grid绘制的数据执行此操作 我用来创建图表的代码如下: graph <- ggplot(slantclean, aes(x = View,value, fill = Texture)) graph + stat_summary(fun.y = mean, geom = "bar", position = "dodge") +

我使用
stat\u summary
从数据中创建了多个条形图。但是,我想手动指定错误条的限制(而不是使用
mean\u cl\u boot
)。如何对使用
facet\u grid
绘制的数据执行此操作

我用来创建图表的代码如下:

graph <- ggplot(slantclean, aes(x = View,value, fill = Texture))

graph + stat_summary(fun.y = mean, geom = "bar", position = "dodge") + 
     stat_summary(fun.data = mean_cl_boot, geom = "pointrange", 
                     position = position_dodge(width = 0.90)) + 
     labs(x = "View", y = "Vertical height of ellipse (cm)", fill = "Texture") + 
     facet_grid( Shape ~ TNOGroup)

graph您可以在
stat\u summary()
中定义自己的函数。如果在
stat\u summary()
中使用
geom=“pointrange”
,则函数应在一个数据帧中给出
y
ymin
ymax

下面是一个示例,让函数
my.fun
计算最小值、最大值和平均值。在
stat\u summary()
中使用时,将为数据中的每个级别计算此值

my.fun<-function(x){data.frame(ymin=min(x),ymax=max(x),y=mean(x))}

graph <- ggplot(slantclean, aes(x = View,value, fill = Texture))

graph + stat_summary(fun.y = mean, geom = "bar", position = "dodge") + 
  stat_summary(fun.data = my.fun, geom = "pointrange", position = position_dodge(width = 0.90)) + 
  labs(x = "View", y = "Vertical height of ellipse (cm)", fill = "Texture") + 
  facet_grid( Shape ~ TNOGroup)

my.fun如果您在ggplot调用之外汇总数据(不依赖于
stat\u summary
),您可能会更成功。然后您可以指定当时错误条的大小,并将汇总数据用作
geom_pointrange
的数据参数。谢谢你的建议。在到达10K@Didzis时,可能会重复祝贺!我不得不按照我原来帖子上的评论去做,因为R奇怪地在计算各组的平均数。不过,这对未来非常有用,谢谢!