Stacked bars

We took a look at stacked bars in Chapter 1, Taking Off with Tableau, where we noted one significant drawback: it is difficult to compare values across most categories. Except for the leftmost (or bottom-most) bars, the other bar segments have different starting points, so lengths are much more difficult to compare. It doesn't mean stacked bars should never be used, but caution should be exercised to ensure clarity of communication.

Here, we are using stacked bars to visualize the makeup of the whole. We are less concerned with visually comparing across categories and more concerned with seeing the parts that make up a category.

For example, at the hospital, we might want to know what the patient population looks like within each type of department. Perhaps each patient was assigned a risk profile on admission. We can visualize the number of visits broken down by risk profile as a stacked bar, like this:

This gives a decent view of the visits for each department type. We can tell that more people visit one of the general departments and that the number of high-risk patients for both general and specialty are about the same. Labs and intensive care see fewer high-risk patients and fewer patients overall. But this is only part of the story.

Consider a stacked bar that doesn't give the absolute value, but gives percentages for each type of department:

Compare the previous two stacked bar charts. The fact that nearly 50% of patients in Intensive Care are considered High Risk is evident from both charts. However, the second chart makes this immediately obvious.

None of the data has changed between the two charts, but the bars in the second chart represent the percent of the total for each type of department. You can no longer compare the absolute values, but comparing the relative breakdown of each department type has been made much easier. Although there are fewer patients in Intensive Care, a much higher percentage of them are in a high-risk category.

Let's consider how the preceding charts can be created and even combined into a single visualization in Tableau. We'll use a quick table calculation, which will be covered in depth in Chapter 5, Diving Deep with Table Calculations. Here, it will only take a few clicks to implement.

Continuing with the Chapter 03 workbook, follow these steps:

  1. Create a stacked bar chart by placing Department Type on Rows, Number of Patient Visits on Columns, and Patient Risk Profile on Color. You'll now have a single stacked bar chart.
  2. Sort the bar chart in descending order.
  3. Duplicate the Number of Patient Visits field on Columns by holding down Ctrl while dragging the Number of Patient Visits field in the view to a spot on Columns, immediately to the right of its current location. Alternatively, you can drag and drop the field from the data pane to Columns. At this point, you have two Number of Patient Visits axes which, in effect, duplicate the stacked bar chart:
  1. Using the drop-down menu of the second Number of Patient Visits field, select Quick Table Calculation | Percent of Total. This table calculation runs a secondary calculation on the values that were returned from the data source to compute a percent of the total. Here, you will need to further specify how that total should be computed.
  2. Using the same drop-down menu, select Compute Using | Patient Risk Profile. This tells Tableau to calculate the percent for each Patient Risk Profile within a given department. This means that the values will add up to 100% for each department.

  1. Turn on labels by clicking the T button on the top toolbar. This turns on default labels for each mark:

After following the preceding steps, your completed stacked bar charts should appear as follows:

Using both the absolute values and percentages in a single view can reveal significant aspects and details that might be obscured with only one of the charts.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset