Stacked bar charts show the proportion of groups (i.e. gender or ratings) that makeup each category (i.e. brand preference), or the "make up" of categories. They are particularly useful when the percentages add up to 100% for the category. This article describes how to use data like below, which is the preferred cola brand cut by gender:
and change it to a stacked bar chart like below which shows the proportion of Males and Females (each color) within each preferred cola brand (each bar):
Requirements
At least one of the following:
- A table with at least two columns and one row.
- Two variable sets that are structured as: Nominal, Binary-Multi, or Binary-Multi (Compact).
Method 1 - Via the visualization menu
- Optional: To automatically hookup a visualization to a table or variable, select the table or variable first.
- From the toolbar, click Visualization
> Bar > Stacked Bar.
- Click on the page where you'd like to place the visualization.
- If you did not make a selection in Step 1, you will use the Properties
> Data > Data Source section to hookup your data.
- To use a table: In the Data field select the table that you want to base the chart on.
- To use variables: In the Variables field, select the variable set you want to use as the categories for each bar. Under Groups, select the variable you'd like to use for the stacking for each bar. Note that using variables as inputs comes with some caveats.
- OPTIONAL: If using variables as inputs, the metric shown on the table will be the Count. If you'd rather show percentages, check Data Manipulation > Convert to percentages/proportions.
- OPTIONAL: Under Chart make additional changes to update the appearance of the visualization.
- Click Calculate and/or ensure that Calculate automatically is checked.
Method 2 - Using an existing table
- Select the table.
- From Properties
, go to Visualization > Bar > Stacked Bar. Your table will be converted to a visualization in-place. You can always see the table again by clicking the Table button in Properties.
- OPTIONAL: Under Chart make additional changes to update the appearance of the visualization.
- Click Calculate and/or ensure that Calculate automatically is checked.
Options
The following is an explanation of the options available in the Properties for this specific visualization. Refer to Visualization Options for general chart formatting options.
Chart
Appearance
- Gap between bars - Specify the amount of space between bars/columns as a proportion of the available space. Values can range from 0 (no gaps) to 0.99 (bars are shown as lines).
- Bar corner radius (% of width) - controls the degree of rounded corners on bar and column charts.
Data Labels
- Minimum threshold to show data labels - Data labels will be hidden in Stacked charts for values that are smaller than this proportion of the total range across all categories in the data. For example, if the longest bar in the chart adds up to 40% and the threshold is set to .3 (or 30%), data values less than 12% (40% * .3) will not be labeled in the chart.
Note
Showing counts:
To show Count instead of a percentage for each bar, use variables as inputs OR use a table that shows the Count statistic. For example, the chart below was created using the same data as above, but replacing the percentages with the Count for each cell:
Important information about editing captions:
Visualization caption edits may not be retained when a visualization with a nested table is switched back to a table. Normally, this only occurs when you double-click the caption and edit the text directly. As a workaround, we recommend using Appearance > Caption > Edit caption to edit your captions.
Showing additional values or metrics
When you show a stacked bar chart of a rating scale, you may also want to show the average rating next to the bars. In any case, when you want to show an additional metric for each bar, you can do so using a separate Table with Custom Formatting output, see How to Align Values to a Visualization Using a Table with Custom Formatting.
Next
How to Create a Clustered Bar Chart
How to Create Several Bar Charts Using Small Multiples
How to Customize the Color of a Single Category in a Bar, Column, or Funnel Visualization
How to Apply a Gradient Palette to a Bar, Column, or Funnel Visualization