Complex grouped bar charts



Hi ggplot users,

I’d like to ask that how to plot grouped bar charts with error bars. For the dataframe below, A, B, C belong to group 1, A2, B2, C2 belong to group 2, etc. In each figure, there are several such groups on x-axis. In each group, there are three bars, while each bar represents the median values in A, B, C, or A2, B2, C2, etc. In each group, bar A is in the y-direction, while bars B and C are in the negative y-direction. The error bars are also shown on each bar variable to summarize all the values from row1 to row10 for example.

Also, though A, and B & C are in the two directions, they share the same x-axis, so that the two directions on y-axis still show positive values, but different variables. I don’t know how to present this on the y-axis label. Could anyone give me some hints on the figure? Thanks for your help.

I also attached a figure about bar charts, but in my case the second and third bars are in the opposite direction with the first bar in each group. I don’t know how to do this, though it is possible to change the values in B and C, B2 and C2, etc, but the labels on y-axis may also change. Thanks.

    A  B  C    A2  B2  C2

1 65 21 54 64 23 55
2 66 23 55 66 22 54
3 54 24 56 70 25 60
4 44 23 53 68 19 49
5 67 22 52 60 18 48
6 66 21 50 54 20 46
7 45 20 51 55 21 51
8 56 19 57 58 22 54
9 40 25 58 59 18 52
10 39 24 53 61 21 48



I see Hadley has already mentioned that you shouldn’t cross-post queries. I would guess that you hadn’t had a reply on the ggplot2 mailing list as it was the weekend.

For your basic issue can I suggest taking look here. That should get you started.

However, if it is a data summary you are interested in, maybe geom_boxplot would be more appropriate than a bar chart?

I’m not convinced that plotting all the variables as positive when two are negative is a good idea. People form a lot of their opinions based on a very quick look, and this would be misleading. I think facetting (on the variable that identifies A,B and C in your long format data.frame) with free y scales would be better. I suppose you could use fill or colour to indicate the positive or negative variables if you are very attached to the idea of plotting them all together.

If you work through the link above you might get to your own solution, or at least be able to generate a minimal reproducible example that people can start from.