Rank Order Data & Stacked Bar Charts

If you have been looking for ways to visualize rank ordered data you might be interested in using stacked bar charts. Rank ordered data is helpful in figuring out which choices are more important and least important to participants in a survey such as favorite sports to watch or what vacation spots a participant is interested in visiting.

I have been using rank order for some survey questions at Webcomm and thought you might be interested in how to visualize that data using R and ggplot2. For this post I am assuming you have some experience with R.

The example we are working with is based on social media platforms that survey participants regularly use. Having a rank of 1 means that it is the platform a participant uses most. In this case we are looking at ranks 1, 2, 3, and 4. If a participant gives a platform a 4 they are telling us they use the platform but there are three other platforms that the participant is using more.

Here is a view of the df which holds the summary data we are working with. If you are unfamiliar with how to get data into a similar type of data frame you might want to check out a few posts on melt.

In the data frame the labels column contains the names of the social media platforms we are ranking (Facebook, Twitter, Instagram, and Snapchat). The rank column keeps track of the percentage of participants who ranked the social media platform as 1, 2, 3, or 4. The value column contains the percentage of participants that provided the rank for each social media platform.

So at this point it is pretty easy to do a basic stacked bar chart in R or R Studio.

The height of each bar in the chart represents the percentage of participants that ranked a social media platform as their 1st, 2nd, 3rd, or 4th frequently used platform. For the sake of this chart we can consider each bar the total percentage of participants that use the social media platform. The sub colors in each bar represents the percentage of participants that ranked a particular social media platform as their 1st (salmon color), 2nd (green), 3rd (blue), and 4th (purple) most used platform.

Notice that for the colors above the initial salmon colored portion it gets hard to estimate the percentages. To make it easier to understand the internal percentages, it makes sense to put the percentages in the middle of each colored section. We’ll need to need to figure out where the middle of each colored portion is in each stacked bar chart to make it look right. Here is a little code that makes it easy: