Skip to content

Layering in Excel

December 5, 2009

Chandoo provides an interesting use of layering Excel objects to add background effects to charts. The example provided suggest many practical uses, but the underlying technique of layering has far broader application and is more powerful than Chandoo’s post indicates.

Layering is the placing of multiple charts and/or shapes over the underlying spreadsheet grid; the objects are made transparent, so multiple layers can be viewed at once. For charts the transaprency is achieved by setting ‘no fill’ for both the plot area and chart area formats. There are several reasons for layering:

  • Integrating multiple charts
  • Integrating charts with non-chart report elements
  • Formatting and customizing charts
  • Creating compound charts

I will cover each of these possible uses of layering. If you have any other uses or examples of layering please indicate in the comments. I assume I am only scratching the surface of this technique.

Integrating multiple charts

In a previous post Integrating report elements in Excel I demonstrate use of a common spreadsheet layer providing unifying zebra stripes and axes to integrate completely different chart types (e.g. stem-and-leaf-plot and scatter plots) or small multiples of the same chart type (e.g. dot plots). Alternatives to integrating multiple charts exist, but layering seems simpler, especially if different chart types are involved.

Integrating charts with non-chart report elements

Chandoo’s post provides a good example of this type of application.

Formatting and customizing charts

One example is creating a colored background. Zebra stripes is one example already noted. Another would be to highlight different time periods or different quadrants or sections of a graph. Jon Peltier provides some examples here and here of how to set background color for charts by using a stacked bar within the chart. However, layering seems to be a far simpler and flexible solution. Consider the following scatterplot. To color the four quadrants, the plot area and chart area backgrounds are set to ‘no fill’ and the plot area is snapped to a 10 x 10 grid of cells, which are colored accordingly. This is effectively the same effect that was achieved with the stacked bar chart method.

layering_chart_background_color_1

However, we can add many different types of chart customization by similarly adding text of formatting the underlying cells. Here sub-quadrants are created with different colors, borders, and labeling.

layering_chart_background_color_2

Another application is highlighting of groups such as quarters and months. Again, only the cells underneath the transparent graph are colored. The following chart was created using layering, which is relatively simple compared to a graph within a graph approach explained by Chandoo .

layering_chart_highlight_month

layering_chart_highlight_quarter

Chandoo’s example is dynamic. Likewise, the cell coloring can be made dynamic with some simple conditional logic within a macro. The benefit here is flexibility. If you wanted a more complicated pattern, it would only be a matter of specifying the colors of ranges of cells. The full code used for this example is as follows (The code is a bit redundant and could be made more concise, but it works for now):

Sub DropDown4_Change()
Call clear_plot_area
With Worksheets("highlight_quarter")
Select Case .range("O16").Value
Case 1
Call format("E19:E30")
Call format("G19:G30")
Call format("I19:I30")
Call format("K19:K30")
Call format("M19:M30")
Call format("O19:O30")
Case 2
Call format("E19:G30")
Call format("K19:M30")
End Select
End With
End Sub
Sub format(range As String)
With Worksheets("highlight_quarter").range(range).Interior
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
End With
End Sub
Sub clear_plot_area()
With Worksheets("highlight_quarter").range("E19:P30").Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub

Creating compound charts

One approach to creating combination charts is to select individual data series and change the chart type just for that data series. This method is explained by John Walkenbach, Jon Peltier, and Chandoo . Layering can also be used as an alternative to this approach. Here is a Pareto chart, which consists of a transparent line graph over a transparent bar graph. The plot sizes are snapped to the same cells so they overlap correctly.

layering_chart_pareto_1

Compared to the aforementioned method, the time to create the graph is roughly the same. However, I think the layering method offers advantages when dealing with more complex types of combinations. Here we have three layers of graphs: two line graphs and a bar chart. The two line charts use different axes.

layering_chart_pareto_2

Conclusion

In sum, layering is a method that is conceptually simple and intuitive, yet is both flexible and powerful in its application. In some cases, alternative methods exist to achieve the same effect as layering, but in nearly every situation layering offers greater flexibility. Moreover, in the absence of layering one would need to learn many different excel tricks, some of which are hard to remember, to perform the same tasks. In contrast, layering is one simple method amounting to little more than removing the chart and plot areas of graphs and using the underlying excel grid or other objects as background.

In a future post I will show how layering can be used to create create rugs and more informative axes.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.