0

My data looks like this.

Serial No.    Control  Treatment  Total    Status   Type
1               2        4          6      social   high
2               3        5          8      social   low          
3               7        8          15     solitary high
4               8        2          10     solitary low
.
.
.

And several more such rows. I want to produce a final graph where I can place mean control, mean treatment and mean total for each of the Status-Types with confidence intervals.

So in the the end, I will have 4 categories on x-axis solitary high, solitary low, social high, social low : each with its corresponding mean control, treatment, total stacked side-by-side.

Thanks! PS I am newbie to ggplot2

  • 2
    Barplots should be used only for count data. If you want to compare means or other statistics, use points or lines (see [this example](http://stackoverflow.com/questions/9531904/plot-multiple-columns-on-the-same-graph-in-r)). A good way to show several statistics together is using `facet_wrap` or `facet_grid`. See [ggplot2](http://docs.ggplot2.org/current/) documentation for more ideas. – Roman Luštrik Mar 15 '16 at 08:21

1 Answers1

0

First Melt you data:

data <- melt(your_data, c(1, 5,6)

ggplot with facets:

ggplot(data , aes(variable, value)) +
    stat_summary(fun.data = 'mean_cl_normal', geom = "bar") +
    stat_summary(fun.data = 'mean_cl_normal', geom = "errorbar", width = 0.5)

I have used mean_cl_normal but you can also use mean_sdl or mean_se or mean_cl_boot as your need. See about these function on help.

TheRimalaya
  • 4,232
  • 2
  • 31
  • 37