Finishing Touches

We can improve the stacked bar chart by adding spacing and sorting the bars by population.

We'll cover the following

We are going to make some final adjustments to the stacked bar chart. First, let’s add some spacing between each bar. They seem too crowded at the moment. Second, we are going to sort the bars. Even though the bars are sorted by state, it would be better if they were sorted by population. The primary focus of this chart is population. Most readers will want to know where their states rank in population.

Adding padding

We will tackle the spacing issue first. We can configure spacing between bars by modifying the band scale. The band scale is responsible for distributing the bars across the x-axis.

We can modify the band scale by adding padding. There are two types of padding we can add, inner and outer padding. We are going to chain two functions called paddingInner() and paddingOuter(). We will pass in 0.1 into both functions.

Get hands-on with 1400+ tech skills courses.