How to Make a Diverging Bar Chart in R

Much of the credit for this blog post goes to Thomas Vroylandt. Before we began working together regularly, I made diverging bar charts but never really understood how things worked. Thomas has helped me truly understand how to make these visualizations.

In a previous life, I worked in the world of program evaluation. In this work, I did a lot of surveys. And in these surveys, we often used Likert scales for answer options. For example:

Question: How good is the education at your school? Answers: Very good, good, bad, very bad.

I had learned from data viz experts like Stephanie Evergreen and Ann Emery that data like this is best shown in a diverging bar chart.

Diverging stacked bar chart example
Source: Ann Emery

At this time, I used Excel for all my visualizations. When I switched to R, I struggled to figure out how to make these charts. It’s taken me a few years, but I’ve finally gotten the hang of making diverging bar charts in ggplot. Here’s my attempt to show how to make diverging bar charts.

And here’s the code to follow along.

There are a few steps to making a diverging bar chart:

  1. Make your negative responses have negative values
  2. Adjust your plot labels so that all positive labels show up
  3. Reorder your bars so they’re in the right order
  4. Make the order of your legend match the bars
  5. Use a diverging fill scale that matches the nature of your data

And here’s what you end up with:

Diverging bar chart example

It might sound daunting, but once you get the hang of it, you can easily make diverging bar charts in R!

Want articles like this in your email? Sign up for the R for the Rest of Us newsletter.

Have any questions? Put them below.

  1. Hi David! Thanks! This is extremely useful.
    I’m struggling to create a diverging bar chart with a survey question that has 5 options instead of 4, mainly on how to handle the neutral answer (nor agree/disagree). Do you have any ideas on how I could build it?
    I appreciate your help a lot!

    1. Glad it’s been helpful! Thomas, who helped me enormously with the code for this blog post, also had an example of just this scenario (which I didn’t include in the original blog post). Take a look at the code here. It breaks the neutral group into two separate groups, then combines them, then plots those separately (although, because both the “positive” and “negative” neutral groups are gray in the final viz, you don’t notice this). Run the code and if you have questions, let me know!