R ggplot:压制geom_bar上的错误栏底部 [英] R ggplot: suppress bottom of error bar on geom_bar

查看:162
本文介绍了R ggplot:压制geom_bar上的错误栏底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用错误条来绘制条形图,但我无法弄清楚如何抑制错误条的下半部分。有人知道我该怎么做吗?

这是我的代码:

  barplot < -  qplot(x = ...,y =平均值,fill =变量,
data = dat,geom =bar,stat =identity,
position =dodge)

barplot + geom_errorbar(aes(ymax = upper,ymin = lower),
position = position_dodge(7),
data = dat)

因此,目标是只有由ymax = upper定义的错误栏部分显示图表,但ymin = lower没有。



我试着给列中的每个单元降低零值,但是这不起作用: p>

  dat < -  transform(dat,lower =0,upper = mean + sem)

>我知道帖子已经过时了,但是现在是我面对这个问题的时候了。如果你想添加一个geom_errorbar到geom_bar,这些选项可以工作,但是如果你想绘制一个geom_point + geom_bar,水平线会出现在你的关键点上。



解决这个问题我找到了一个'陷阱'。

  ggplot(data,(aes(x ...)+ geom_point( )+ 
geom_errorbar(aes(ymin = upper,ymax = upper))+
geom_linerange(aes(ymin = mean,ymax = upper))
pre>

使用此代码,您将只获取上一行,因为下面一行与上面的行重叠,并且与 geom_linerange 你得到垂直线。


I'm plotting bar plots with error bars but I can't figure out how to suppress the lower part of the error bar. Does anyone has an idea how I could do that?

This is my code:

barplot <- qplot(x=..., y=mean, fill=variable,
             data=dat, geom="bar", stat="identity",
             position="dodge")

barplot + geom_errorbar(aes(ymax=upper, ymin=lower), 
                    position=position_dodge(7),
                    data=dat)

So, the goal is that only the part of the error bar that is defined by "ymax=upper" shows in the graph but "ymin=lower" does not.

I tried with giving each cell in the column "lower" the value zero but this didn't work:

dat<- transform(dat, lower="0", upper=mean+sem)

Well, thanks in advance!

解决方案

I know that the post is old, but it is now when I front this problem. These options work if you want to add a geom_errorbar to a geom_bar, but if you want to plot a geom_point + geom_bar, an horizontal line will appear over your point.

For solve that problem I have found a 'trap'.

ggplot(data, (aes(x...) + geom_point() + 
geom_errorbar(aes(ymin = upper, ymax = upper)) + 
geom_linerange(aes(ymin = mean, ymax = upper))

Using this code you will obtain only the upper line, because the lower line is overlapping the upper, and with geom_linerange you get the vertical line.

这篇关于R ggplot:压制geom_bar上的错误栏底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆