PTS Blog

Main menu:

PTS Utilities

Commercial Utilities developed by Peltier Technical Services

  Waterfall Chart
  Box and Whiskers
     Coming soon!


 

Excel Books

Books that I own and use while developing in Excel

Goods and Services

Excel or charting related products and services which I use or feel are worthwhile additions

Subscribe

Subscribe

Site search


Recent Posts

Recently Commented

Popular Posts

Archive


 

Categories


 

Clustered-Stacked Column Charts with Vertical Separators

by Jon Peltier
Peltier Technical Services, Inc., Copyright © 2008. All rights reserved.

One of my most popular blog posts of all times is Clustered-Stacked Column Charts. This post has received the most visits and is the most heavily commented post I’ve written. One reader wants to know how to add vertical lines between the clusters. This is an adaptation of the technique in Add a Vertical Line to a Column or Line Chart: Error Bar Method. I’ll rebuild the clustered stacked chart, then add the lines.

Clustered Column Chart

Suppose we have the simple data below, with four series of data over three months. One series is to be by itself in the left column of the cluster, and three series stacked on the right.

Clustered Column Chart Data

We can select this data and create a clustered column chart

Clustered Column Chart

or a stacked column chart

Clustered Column Chart

But however we try to arrange series, we cannot achieve a clustered-stacked chart.

If we keep our wits about us, we can envision a worksheet arrangement that will give us what we want. We need a gap, one series stacked in the first filled slot, three series stacked in th second slot, then another gap, and the pattern repeats. So this is really a stacked chart. Where we have gaps, the series have zero values; where one series is alone, the others have zero values; where the three series are stacked, the other has a zero. This new arrangement is shown below. Gaps in the data occur at columns B, E, H, and K. The left column of each cluster has data in columns C, F, and I; the right column in D, G, and J. For clarity in this exercise, I’ve duplicated the column letters in the category labels range (B7:K7, tan). The top left cell (A7) is blank.

Clustered Column Chart Data

Select this range and create a stacked column chart. It’s halfway done, we just need some formatting.

Clustered Column Chart

Change the gap width of any series to zero, and it looks almost done.

Clustered Column Chart

The axis labels aren’t right, though. We need the months centered between existing labels, for example, “Jan” between the current positions of “C” and “D”. This simple data works; note its arrangement parallels the original data. I’ve used 10 for the values so the bars show up in the charts. When I finish I’ll change the values to zero.

Clustered Column Chart Data

Here is what the chart’s axis should look like when we’re done:

Clustered Column Chart

Copy the data in F1:I2, select the chart, and use Paste Special to add the data as a new series, with data in rows, category labels in the first row (we’ll have to reapply this later), and series names in the first column. The data is stacked on top of the first three categories.

Clustered Column Chart

What we need to do is put the axis series on the primary axis and the stacked data series onto the secondary axis (if we reverse this, we will have problems displaying the Jan-Feb-Mar axis labels). Select one of the series, and move it to the secondary axis. I usually move the lowest valued series first (Right 3 in this example) so that the secondary axis series don’t obscure the primary series I need to select and move next.

Clustered Column Chart

In turn, select and move all of the Left and Right series to the secondary axis. I’ve changed the gap width of the Axis series to 100% (from zero) to make it easier to follow. The Left and Right series are clustered, not stacked, because that’s Excel’s default column chart variation.

Clustered Column Chart

Select one of the secondary axis series, and change its chart type to stacked. All column series on that axiss will follow suit. Also, change the gap width of a secondary axis column to zero.

Clustered Column Chart

Excel has given us a secondary value (Y) axis, but we only have the primary category (X) axis. Using Chart menu > Chart Options > Axes tab, or in Excel 2007, the Chart Tools > Layout tab, to add the secondary axis to the chart. At first, we don’t have the month names as our labels, because Excel applied the existing labels (B through K) to all series.

Clustered Column Chart

Edit the series source data or the series formula for the Axis series, so that the months in G1:I1 are used for category labels.

Clustered Column Chart

Almost done. The month names are not centered correctly under the clustered columns. Format the scale of the secondary category axis (B through K at the top of the chart) so that the value axis does not cross between categories.

Clustered Column Chart

Perfectly aligned. Now format the secondary category axis to display no tick labels and no tick marks.

Clustered Column Chart

Use Chart menu > Chart Options > Axes tab or Ribbon > Chart Tools > Layout tab to remove the secondary value (Y) axis (or select it and press Delete). Format the Axis series on the secondary axis so that it has no fill. Change the Axis series values in G2:I2 from 10 to zero. Select the legend, then select the Axis legend entry, and hide it by pressing Delete.

Clustered Column Chart

Adding Vertical Lines - The Easy Way

As Andy Pope pointed out in his comment, there’s a very easy way to add vertical lines between the main categories. Since the categories are on the primary X axis, we can add major gridlines to this axis. Right click on the chart, choose Chart Options, click on Gridlines, and check Major Gridlines under Category (X) Axis.

Clustered Column Chart

Adding Vertical Lines - The Hard Way

To add the vertical lines the hard way (as I originally posted), we first will add a series of points along the lower edge of the chart. This will be an XY type series, and we will apply vertical error bars. The data for this series is as follows. Jan is at 1, Feb is at 2, and Mar is at 3; we want points between these positions, so we need X values of 1.5 and 2.5. The Y values are zero so the points lie along the horizontal axis.

Clustered Column Chart

Copy the range K1:M2, select the chart, and use Paste Special to add the data as a new series, with data in rows, categories in the first row, and series names in the first column. The data is first added as another stacked column series, with zero height, so it’s not visible.

Clustered Column Chart

Select the Verticals series (perhaps by selecting a visible series and using the arrow keys to cycle among the series in the chart), and from the Chart menu, click on Chart Type, then select an XY type. I chose the type  with markers and lines just to be visible in this example.

Clustered Column Chart

If you look closely, you can see that the secondary category axis has changed, moving the outer clusters closer to the center. Select the secondary category axis (I used the Chart Element dropdown on the Chart toolbar), on the Format menu, choose Selected Axis, and on the Scale tab, uncheck the box for Value (Y) Axis Crosses Between Categories.

Clustered Column Chart

That’s better. Now double click the Verticals series, click on the Y Error Bars tab, click on the positive error bar icon, and enter a value of 70. If the Y axis has an automatic scale, it will change to 80, so it reaches higher than the error bars, so you will have to enter 70 as the axis maximum for the Y axis.

Clustered Column Chart

Now hide the Verticals series by formatting it with no markers and no lines. Select the legend, then select the Verticals legend entry, and press Delete.

Clustered Column Chart

Now you have the vertical separation between months of data. In fact, this is a panel chart.

Possibly Related Posts:

If you liked this entry, please bookmark and share it:
  • Digg
  • del.icio.us
  • Facebook
  • Technorati
  • TwitThis
  • StumbleUpon
  • Google
  • Reddit

Comments

I welcome comments from my readers. If you have an opinion on this post, if you have a question or if there is anything to add, I want to hear from you. Whether you agree or disagree, please join the discussion.

Read the PTS Blog Comment Policy.


Comment from Tony Rose
Time: Thursday, October 2, 2008, 10:48 pm

Jon - great tutorial!

My fundamental question is wouldn’t a line graph be a better choice for comparing segments over time? I always get leery when I see stacked bar charts because of the dissimilar baseline issue. What are your thoughts?


Comment from Jon Peltier
Time: Friday, October 3, 2008, 7:15 am

Tony -

The use of months in this case was just for illustration. Perhaps I should have chosen something else, like department (for sales vs costs).

The dissimilar baseline is an issue in stacked charts. Any chart like this, which emphasizes the total height of each stack, should be backed up by charts that break out the values so they can be readily compared. Drill down, right?


Comment from Andy Pope
Time: Saturday, October 4, 2008, 10:15 am

Hi Jon,

As the primary axis is based on the 3 month names why not simply use the Major grid lines rather than an extra series and error bars?


Comment from Jon Peltier
Time: Saturday, October 4, 2008, 10:47 am

Andy -

Well, I’m embarrassed. That’s exactly the way to do it. No worries about extra dummy series or axis scales or anything.


Comment from Andy Pope
Time: Saturday, October 4, 2008, 10:52 am

when we have to work around so many features it’s all to easy to miss the obvious :)


Comment from Jon Peltier
Time: Saturday, October 4, 2008, 10:54 am

I’ve updated the post. Here I am showing people how to use one chart feature to mimic a missing feature, when I’m really reinventing the wheel, showing poeple how to use one feature to mimic another existing one.


Comment from Tony Rose
Time: Saturday, October 4, 2008, 12:51 pm

Jon, it happens. I too, like so many others, am guilty of over analyzing things or generating complicated solutions to simple problems. Like Andy said, there are so many work-arounds that are done, sometimes the built-in features are forgotten about.

Keep up the great work!


Comment from talia
Time: Wednesday, October 8, 2008, 8:26 am

jon,

this is amazing! I’ve been looking for this for so long!

by the way, this may be a stupid question, but I can’t get the verticals to go all the way up to the upper axis.
I followed your instructions and put 70 on the positive Y Error Bar, yet it’s only reaching about 60~. Any ideas on this error?

thanks again!


Comment from Jon Peltier
Time: Wednesday, October 8, 2008, 8:43 am

Talia -

Two suggestions:

1. Try the easier major category axis gridlines, suggested by Andy Pope and now built into the post.

2. When using error bars, if the Y axis maximum is not fixed, it will increase so that the entire error bar fits into the scale with white space above. Therefore you have to fix the Y axis maximum to match the error bar value.


Comment from talia
Time: Wednesday, October 8, 2008, 7:41 pm

Jon,

the first method doesn’t work for me, because i have categories within the major gridlines (for example, week 1, week 2, week 3, week 4 within each of the months in your chart).

my Y axis max is fixed at 70, yet still not working. I’ll try to just build it from the start, but I honestly have no explanation.

thanks again. your tutorials are the best I’ve ever seen so far!


Comment from Jon Peltier
Time: Wednesday, October 8, 2008, 9:43 pm

Talia -

The first method will break down if the cluster arrangement is more complicated (e.g., some months have four weeks, some have five).

If the Y axis max is 70, and the error bar length is 70, they ought to match up. Make sure you only have a primary Y axis, not a secondary Y axis with a non-fixed maximum scale.

Write a comment





Subscribe without commenting

Create Excel dashboards quickly with Plug-N-Play reports.