Peltier Tech Blog

Excel Chart Add-Ins | Training | Custom Solutions | Charts and Tutorials | PTS Blog

 

Main menu:

 
Peltier Tech
Chart Add-Ins

Peltier Tech Waterfall Chart Utility
Peltier Tech Cluster-Stack Chart Utility
Peltier Tech Box and Whisker Chart Utility
Peltier Tech Marimekko Chart Utility
Peltier Tech Dot Plot Utility
Peltier Tech Cascade Chart Utility

 
Excel Dashboards

Subscribe

Site search

Subscribe

Site search


Recent Posts

Recently Commented

Popular Posts

Archive


 

Categories


 

Privacy Policy

Creative Commons License
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

Clustered-Stacked Column Charts with Vertical Separators

by Jon Peltier
Thursday, October 2nd, 2008
Peltier Technical Services, Inc., Copyright © 2010.
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

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.

Related Posts:

Bookmark and share this entry:
  • Twitter
  • Digg
  • Facebook
  • LinkedIn
  • del.icio.us
  • Technorati
  • StumbleUpon
  • Google Bookmarks
  • Reddit
  • MySpace
  • Slashdot
  • Yahoo! Buzz
  • Tumblr

Learn how to create Excel dashboards.

Comments


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.


Comment from Christopher
Time: Friday, November 21, 2008, 11:44 am

Jon,

Is it possible to make a chart like this dynamic? I am trying to make a clustered-stacked column chart that can have anywhere from 8 to 30 “main categories”. Any ideas on this would be greatly appreciated.

Your tutorials are a life saver. Thank you for your time and dedication.


Comment from Jon Peltier
Time: Friday, November 21, 2008, 12:22 pm

Christopher -

Anything that you can do, you could in principle program in VBA. You need to start with a compact data range, lay it out in a sparse array with a particular arrangement, then spit out a chart. The challenge is to make the VBA program as smart as you arem when it comes to knowing how best to lay out the data.

I’ve thought about writing a utility to do this, and on a recent plane trip I even sketched it out. There hasn’t been enough time of the free variety for me to work on it beyond that, especially since I have to waste so much time sleeping. Someday….


Comment from petya
Time: Monday, February 9, 2009, 4:44 pm

Jon,

is it possible to have several clustered-stacked columns for one category, and then only one stacked column for others? For example, category 1 has 2 clustered bars that are both stacked, category 2 only has one, category 3 has 2, etc. Also, I need the clustered-stacked columns in each category to be closer together than the rest of the categories. Is that possible to plot in one graph?

Thanks!


Comment from Jon Peltier
Time: Monday, February 9, 2009, 8:26 pm

Petya -

You can follow the same protocol, though you need to be watchful of the details. In this example, note that I have blank columns outside each end of the data (B and J) and blank columns between each stacked block (E and G). The two stacks for Jan are in C and D, the one stack for Feb is in F, and the two for Mar are in H and I.

The month labels don’t really match up here, but it’s not far off. You may need to use another technique to produce these labels, though, using a hidden XY series and its data labels.

Data for cluster stack chart with uneven clusters

Cluster stack chart with uneven clusters


Comment from petya
Time: Tuesday, February 10, 2009, 12:29 pm

Jon,

Thank you once again. Your help is priceless!


Comment from Michael Saba
Time: Saturday, April 18, 2009, 11:33 pm

stacked Chart
Firstly Jon thanks for your great site. I constructed a stacked line chart successfully in excel 97-2003, but when i upgraded to excel 2007 the chart labels would not show. I have tried lots of things to fix, such as relabelling with the XY labeller, but it wont work, do I have to rebuild again or is it a quirk in 2007.
thanks
PS if there is a commercial version I would be wiling to buy

Mike


Comment from Jon Peltier
Time: Sunday, April 19, 2009, 7:25 am

Hi Mike -

There’s no commercial version of Rob’s Chart Labeler, though others sell similar products. I haven’t tried any of these other labelers, but I doubt they’re as comprehensive or well-built as Rob’s. Rob did release a version that works with 2007, but that was some time ago, so you probably have it if you downloaded it after reading my article.

Can you get any labels to appear where you want your custom labels? Select the series, go to Data Labels on the Chart Tools > Layout tab, and add any type of labels to the chart.


Comment from Tammi Belden
Time: Thursday, July 23, 2009, 6:40 pm

I might be interested in buying the Cluster-Stack Column Chart Utility but I have one question. If someone else accesses the same excel file and does not have the utility on their computer, what will the chart look like?


Comment from Jon Peltier
Time: Thursday, July 23, 2009, 9:41 pm

Tammi -

The chart is a regular Excel chart, with a data layout which is tedious to set up manually. The utility lays out the data automatically and creates the chart. After that, the chart remains unchanged, unless of course someone edits it. Whether the utility is present or not has no effect on its subsequent appearance.


Comment from Julia
Time: Thursday, April 1, 2010, 1:08 pm

Hello Jon,

I’m making my very first clustered-stacked cloumn chart in order to track the forecast and actual sales bookings and I’m having some difficulties to centered the axis. Could you please detail a little bit more how to:

“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.”

Thank you very much, Julia


Comment from Jon Peltier
Time: Thursday, April 1, 2010, 1:14 pm

Julia -

This depends somewhat on your version of Excel.

1. Right click on the upper horizontal axis.

2. Choose Format Axis from the pop up menu

3a. 2003 and earlier: On the Scale tab, uncheck “Value (Y) Axis Crosses Between Categories”.

2b. 2007 and later: On the Axis Options tab, under Position Axis near the bottom, select “On Tick Marks”.


Comment from MK
Time: Thursday, June 10, 2010, 3:07 pm

Jon,
your lessons are great. I have a learnt a lot here than I have ever done before. One question – is it possible to creat another axis in a stacked chart. Like for instance, I have two companies and their various departments and workforce within their depts; the 2 companies are plotted on the X axis and the dept headcount are stacked. Is it possible to add a third segment to it to show expenses for each category? Thanks.


Comment from Jon Peltier
Time: Thursday, June 10, 2010, 8:34 pm

MK -

You would not want to stack a segment using a second set of units (secondary axis) onto an existing stack of segments plotted on the first set of units (primary axis). Apples and oranges and all that.


Comment from MK
Time: Sunday, July 4, 2010, 9:55 pm

Thanks Jon. I understand.

Write a comment

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.

If you want to include an image in your comment, post it on your own site or on one of the many free image sharing sites, and include a link in your comment. I'll download your image and insert the necessary html to display the image inline.

Read the PTS Blog Comment Policy.





Subscribe without commenting

Peltier Tech Waterfall Chart Utility Peltier Tech Cluster-Stack Chart Utility Peltier Tech Box and Whisker Chart Utility Peltier Tech Marimekko Chart Utility Peltier Tech Dot Plot Utility Peltier Tech Cascade Chart Utility

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