Luis Verde Arregoitia

Computer scientists, psychologists, and statisticians have all studied how to create visualizations that communicate data effectively. Graphical perception experiments showed that the human visual system is pretty good at decoding numerical data mapped to the spatial position of a graphical feature (Heer et al. 2010). This may be why bar charts are so popular and widely-used.

CCO image

To show counts or frequencies of observations for different groups, we can make the length of the bars represent the corresponding values. The problems start when bar charts are also used to show multiple observations for each group. What usually happens is that the length of the bars now represent the group means, and then silly-looking error bars are drawn on top to show standard errors or standard deviations for the means. These plots are also known as ‘dynamite plunger plots’ because they look like the detonator boxes from cartoons.

CCO image

Bar charts for multiple observations are not good because:

they conceal the underlying data, so we cannot see the its distribution or the sample size

they look pretty lame

I’m writing this quick post after teaching a ggplot workshop last month, followed by attending two biology conferences where I saw these plots used by students, plenary speakers, bioinformaticians, and various other researchers. In 2016, Helena Jambor also noted how prevalent these charts are, even in top journals.

Alternatives to the bar chart

I’m not the first to call for less of these plots, but I want to share some alernatives that I haven’t seen implemented too often.

First of all, why draw bars if we can show the underlying data points, or at least show more information about the distribution of the data, or some nice parametric summaries (e.g. box plots, violins, etc.).

This tweet speaks for itself, and all those options can be made in ggplot with the right packages and extensions (e.g. ggforce and ggbeeswarm).

If for some reason we absolutely need to plot bars for multiple observations per group, the approach below may be an option.
At this point it’s pretty hacky, but I think something like this could be made into a custom geom by anyone who is good at ggproto.

Here’s how it works:

Generate random values within the bounds of the mean plus or minus the standard error.

Overlay semi-transparent bars to show the range of the standard error.

Draw a bar with an outline but no fill to show the point estimate (the mean).

This is not meant to show the sample size or underlying distribution of the data, but it shows the estimates and standard errors without looking as lame. I was mostly interested in learning the data manipulation steps needed to generate the random values. I have to admit that I could not figure out how to add the layers iteratively, so there is a lot of copying and pasting.

Let’s work through the typical bar charts first:

These are the means for one of the variables (total sleeping time) in the built-in mammalian sleep dataset, by dietary guild.