About error bars on barplots

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

About error bars on barplots

lily li
Hi R users,

I have a question about adding uncertainty bars to stacked bar plots.

DF:
  year   A   B   C   Amin  Amax  Bmin  Bmax  Cmin  Cmax
 2009  40  45  15   30      61       23       56      14       17
 2010  36  41  23   26      54       22       51      22       24

I use the code below:

DF.refm = melt(subset(DF[,c(1:4)]),id.vars='year',variable_name='Legend')

fig1 = ggplot(data=DF.refm, aes(x=year,y=value,fill=Legend))+
  geom_bar(stat='identity',size=.5)+ theme_bw()+ xlab('Year')+
ylab('Percent (%)')
print(fig1)

But I don't know how to change it a little bit. For example, how to add the
error bars on the plot, as is shown in the figure below? The error bar for
variable A ranges from Amin to Amax, the same applies to variables B and C.
Thanks for your help.
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [FORGED] About error bars on barplots

Rolf Turner
On 18/06/17 12:10, lily li wrote:

> Hi R users,
>
> I have a question about adding uncertainty bars to stacked bar plots.
>
> DF:
>    year   A   B   C   Amin  Amax  Bmin  Bmax  Cmin  Cmax
>   2009  40  45  15   30      61       23       56      14       17
>   2010  36  41  23   26      54       22       51      22       24
>
> I use the code below:
>
> DF.refm = melt(subset(DF[,c(1:4)]),id.vars='year',variable_name='Legend')
>
> fig1 = ggplot(data=DF.refm, aes(x=year,y=value,fill=Legend))+
>    geom_bar(stat='identity',size=.5)+ theme_bw()+ xlab('Year')+
> ylab('Percent (%)')
> print(fig1)
>
> But I don't know how to change it a little bit. For example, how to add the
> error bars on the plot, as is shown in the figure below? The error bar for
> variable A ranges from Amin to Amax, the same applies to variables B and C.
> Thanks for your help.


Your figure did not come through, at least not to me.  You are probably
doing something fancy, and the mailing list software stripped out the
figure.  *Do* learn to keep things simple.  _Attach_ figures as *.pdf
files, for instance.

That being said, to answer your question, my advice (and that of many
others) is: DON'T.  Error bars on boxplots (such plots are sometimes
known as "dynamite plots" or "detonator plots") are considered by the
cognoscenti to be abominations.

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [FORGED] About error bars on barplots

lily li
Okay, thanks for letting me know. I found the plot from website so thought
there may be a way. I just converted the format of the figure, and
attached. But I don't mean to use it as you suggested. Thanks.

On Sat, Jun 17, 2017 at 6:30 PM, Rolf Turner <[hidden email]>
wrote:

> On 18/06/17 12:10, lily li wrote:
>
>> Hi R users,
>>
>> I have a question about adding uncertainty bars to stacked bar plots.
>>
>> DF:
>>    year   A   B   C   Amin  Amax  Bmin  Bmax  Cmin  Cmax
>>   2009  40  45  15   30      61       23       56      14       17
>>   2010  36  41  23   26      54       22       51      22       24
>>
>> I use the code below:
>>
>> DF.refm = melt(subset(DF[,c(1:4)]),id.vars='year',variable_name='Legend')
>>
>> fig1 = ggplot(data=DF.refm, aes(x=year,y=value,fill=Legend))+
>>    geom_bar(stat='identity',size=.5)+ theme_bw()+ xlab('Year')+
>> ylab('Percent (%)')
>> print(fig1)
>>
>> But I don't know how to change it a little bit. For example, how to add
>> the
>> error bars on the plot, as is shown in the figure below? The error bar for
>> variable A ranges from Amin to Amax, the same applies to variables B and
>> C.
>> Thanks for your help.
>>
>
>
> Your figure did not come through, at least not to me.  You are probably
> doing something fancy, and the mailing list software stripped out the
> figure.  *Do* learn to keep things simple.  _Attach_ figures as *.pdf
> files, for instance.
>
> That being said, to answer your question, my advice (and that of many
> others) is: DON'T.  Error bars on boxplots (such plots are sometimes known
> as "dynamite plots" or "detonator plots") are considered by the cognoscenti
> to be abominations.
>
> cheers,
>
> Rolf
>
> --
> Technical Editor ANZJS
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

sample.pdf (26K) Download Attachment
Loading...