[R] Stacked geom_bar with aggregated SE -ggplot2
jrkrideau at inbox.com
Tue Apr 30 18:12:06 CEST 2013
Welcome to the R-help list.
Are you seriously proposing to add error bars to a stacked barplot? Why?
Do you mean a dodged barplot?
My first thought is that there probably are several better ways of presenting your data than stacked bar charts--I sometimes think that anything other than pie charts beats a stacked bar chart.
It might help to have some idea of what you are trying to do. We really need a concise statement of the problem in subject matter terms--probably a bit of an expansion on what you provided at the end of your post and then some example data and what code you have been working with. Definately look at ?dput as a way to provide the sample data.
Have a look at https://github.com/hadley/devtools/wiki/Reproducibility for some suggestions on how to put frame a question for the R-help list.
Kingston ON Canada
> -----Original Message-----
> From: olivia.burge at gmail.com
> Sent: Wed, 1 May 2013 00:20:59 +1200
> To: r-help at r-project.org
> Subject: [R] Stacked geom_bar with aggregated SE -ggplot2
> Hi there,
> I've been battling with an extension of this in my own data: getting
> appropriate error bars once data is stacked in a bar graph.
> (original question:
> td3311176.html). It wouldn't let me reply to that thread.
> A modification of the earlier answer:
> diamonds_df <- ddply(diamonds, .(cut, color), summarise,
> mean_price = mean(price),
> se_price = sd(price)/sqrt(length(price))
> limits <- aes(ymax = mean_price + se_price, ymin = mean_price -
> a<-ggplot(diamonds_df, aes(x = cut, y = mean_price, fill=color)) +
> Then attempting to add error bars:
> a+ geom_errorbar(limits, position=position_stack(width=0.9), width=0.9)
> I have tried:
> r + stat_sum_df("mean_cl_normal", geom = "errorbar"), using the
> function in http://www.stanford.edu/~paunesku/, using ddplyr but haven't
> managed to work out a way of specifying the error bars to R. In my case
> would like to use an error bar analogous to each value of "cut" in the
> example. When I calculate the SEs appropriately ggplot2 won't stack.
> This is first time posting and I've scoured the various forums and
> for a worked example.
> In case it is relevant, my response variable is fitted germination of an
> lmer model ("germination"), x is a categorical variable (treatment, with
> levels), and I am using a categorical variable ("species") to stack.
> Kind regards,
> MSc student
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
More information about the R-help