Peltier Technical Services, Inc.
 

Excel Charting Utilities | Custom Solutions | Training | Charts and Tutorials | PTS Blog


Peltier Tech
Chart Utilities

PTS Waterfall Chart Utility
PTS Cluster-Stack Column Chart Utility
PTS Box and Whisker Chart Utility
PTS Marimekko Chart Utility
PTS Dot Plot Utility
PTS Cascade Chart Utility

 

PTS Excel Box and Whisker Plot (Box Plot) Utility Documentation


Box and Whisker Charts (Box Plots)

Box and Whisker Charts (Box Plots) are commonly used in the display of statistical analyses. Unfortunately, Microsoft Excel does not have a built in Box and Whisker chart type. You can create your own custom Box and Whisker charts, using stacked bar or column charts and error bars, in combination with line or XY scatter chart series to show additional data.

Elsewhere on this website there are tutorials showing how to construct box and whisker charts in Excel. This is a tedious manual process, however, and this page describes a utility I've written that enables you to easily make such charts automatically. You can use the straightforward dialogs to build box and whisker plots, or you can call this utility from your own VBA procedures.


About the PTS Box and Whisker Chart Utility

The Peltier Technical Services (PTS) Box and Whisker Chart utility allows the user to construct box and whisker charts directly from raw data; the utility builds an intermediate summary table and then creates and formats the chart from this table. The utility is designed to work in Windows Excel versions 2000 through 2007.


Installing the PTS Box and Whisker Chart Utility

If you have installed an earlier (demo) version of this utility, you should uninstall that version before continuing. Choose Add-ins from Excel's Tools menu, locate Box Charting Utility in the list of add-ins, uncheck the box in front of the entry, and press OK.

To install the Box Chart utility, close Excel, then double click on the PTS_Box_Charter_Setup.exe. The Box Chart utility is installed as an add-in, in a new "PTS Charts" subdirectory of your computer's Program Files directory. In addition, "DataBoxPlot.xls", a workbook containing sample data to show how to use the utility, is saved in "PTS Charts", a new subdirectory in your My Documents directory.


Using the PTS Box and Whisker Chart Utility

When you install the add-in in Excel 2000 through 2003, it adds a menu called PTS Charts to Excel's Worksheet Menu. In Excel 2007, the utility adds a custom PTS Charts ribbon. The utility then adds a "Box and Whisker Chart" button to the menu or ribbon. Select a range of data to chart, click this Box and Whisker Chart button, and the dialog appears.


 

About the Data

The Box and Whisker Utility is designed to calculate statistics on a range of raw data. A frequent question I've received from users is "How can I use the utility to chart data which has already been compiled?" I always have said that this feature is not supported, but maybe it will be incorporated into a future version of the utility.

I recently had an "aha!" moment. Use a five-value range as input into the utility, where those five values represent calculated minimum, 25th percentile, median, 75th percentile, and maximum. For all quartile calculations except for Minitab's, the utility's calculated quartile breaks based on the compiled input values match the compiled input values. Therefore the utility has had the requested capability all along. Naturally this applies only to the box and whisker quartiles and four box quartiles options, and not to the box and whisker with outliers style. You should ignore the calculated averages, since the average of these five parameters is meaningless. If you have average values, you can paste them in the output table where the calculated values are stored.

The Box and Whisker Charter dialog is shown at right.

If the selected range contains chartable data, it is indicated in the range selection box at the top of the dialog. If the selected range contains no data, or if the selection is not a range, this box is empty. If the selected range consists of a single cell, the utility identifies the range of data surrounding the active cell in the range selection box, just as the Chart Wizard does. If the selection is larger than one cell, the utility identifies only the selected range in the box. If the selected range consists of multiple discontiguous areas, you may get unpredictable results.

The utility detects whether the data is arranged by row or by column, and also whether the data has labels in the first row or column of the range. You can override these settings.

You can select your chart's orientation and style. Selections made here are repeated the next time the utility is used.

    

Output of the Utility

The output produced by this utility consists of a new worksheet with a data table and an embedded chart. The chart is a standard Excel chart, somewhat larger than the Chart Wizard's default size; it can be moved, resized, and otherwise formatted as any other Excel chart. The chart is a combination chart with a number of stacked column or bar series and line or XY series.

Notice that the stacked columns in vertically aligned box plots are aligned directly above the columns of data in the worksheet. This alignment is maintained for any number of categories across the chart and table, as shown below. The sizes of horizontal box and whisker charts are also adjusted to keep the charts on screen while maintaining a reasonable aspect ratio.

The chart width varies with number of categories


PTS Box and Whisker Chart Options

The Box and Whisker Utility produces three styles of box plots: Simple Box and Whisker Chart, Four Box Quartile Chart, and Box and Whisker Chart with Outliers.

Simple Box and Whisker ChartFour Box Quartile ChartBox and Whisker Chart with Outliers

Box and whisker quartile chart

The inner quartiles of each sample are represented by light gray boxes, separated at the median by a thin line. The lower and upper quartiles are represented by whiskers. The average of each sample is represented by a diamond marker overlying the box and whisker for that sample.

Four-box quartile chart

The inner quartiles of each sample are represented by medium gray boxes, separated at the median by a thin line. The lower and upper quartiles are represented by light gray boxes. The average of each sample is represented by a diamond marker overlying the box and whisker for that sample.

Box and whisker chart with outliers

The inner quartiles of each sample are represented by light gray boxes, separated at the median by a thin line. The height of the gray boxes together makes up the interquartile (IQ) range. The range of data falling within 1.5 interquartile ranges of the median is represented by whiskers. Any outliers that fall between 1.5 and 3 IQ ranges from the mean are represented by asterisk markers, while any outliers falling beyond 3 IQ ranges from the median are represented by circular markers. The average of each sample is represented by a diamond marker overlying the box and whisker for that sample.

Each of these box and whisker chart styles is available in vertical (column) and horizontal (bar) variations.

Vertical Box and Whisker Chart with OutliersHorizontal Box and Whisker Chart with Outliers

The Box and Whisker Utility computes quartiles in four different ways, which can be changed on the fly by the user: Tukey hinges, CDF quartiles, Minitab quartiles, and Excel quartiles. The Tukey and CDF techniques are generally close to each other (identical in the data set below and therefore shown in just the first chart), Minitab calculates the widest interquartile ranges (fewer outliers), and Excel calculates the narrowest interquartile ranges (more outliers).

For my definitions of quartiles, I have relied on Quartiles in Elementary Statistics by Eric Langford, California State University, Chico, published in Journal of Statistics Education Volume 14, Number 3 (2006).

Outlier Box Chart using Tukey Hinges or CDF QuartilesOutlier Box Chart using Minitab QuartilesOutlier Box Chart using Excel Quartiles

The user can toggle the display of averages by checking the checkbox.

Box Chart With AveragesBox Chart Without Averages

The user can toggle the display of outliers in a Box and Whisker Chart with Outliers by checking the checkbox.

Box Chart With OutliersBox Chart Without Outliers

All of these box and whisker charts are "normal" Excel charts, made from a combination of common chart types, so they can be resized, reformatted, and copy-pasted into other files and applications. The user should make a copy of a chart, and make changes to the copy, to prevent the loss of work if the only chart is edited beyond recognition.


Using the PTS Box and Whisker Chart Utility Programmatically

The core of the PTS Box and Whisker Utility is a procedure called PTS_BoxWhiskerChart, which can be called from other VBA procedures. The syntax of the PTS_BoxWhiskerChart function is:

        Function PTS_BoxWhiskerChart(rngData As Range, _
                                     bByColumn As Boolean, _
                                     bFirstLabels As Boolean, _
                                     bVertical As Boolean, _
                                     lBoxWhiskerChartStyle As BoxWhiskerChartStyle) _
                                     As Chart

rngData is the range containing the raw daya, bByColumn is true if the data is arranged by columns, bFirstLabels is true if the first row or column of the data contains labels for each set of data, bVertical is true to create a vertical (columnar) chart, and lBoxWhiskerChartStyle represents the style of chart, where 0 is a box and whisker quartile chart, 1 is a four box quartile chart, and 2 is a box and whisker chart with outliers. The newly created box and whisker chart is returned by the function to the calling procedure for further execution.

The simplest way to use the PTS Box and Whisker Chart Utility from your own code is to call it using Application.Run, as in the following sample macro. The PTS_BoxWhiskerChart procedure is a function, which returns the box and whisker chart to the calling procedure.

Sub TestBoxCharterAppRunFunction()
  
  Dim chtBoxWhisker As Chart
  
  Set chtBoxWhisker = Application.Run("'PTSBoxPlotter.xla'!PTS_BoxWhiskerChart", _
      ActiveSheet.Range("B2:E40"), True, True, True, 1)
  
End Sub

The PTS_BoxWhiskerChart procedure can also be called as a sub, without returning any results to the calling procedure.

Sub TestBoxCharterAppRunFunction()
  
  Dim chtBoxWhisker As Chart
  
  Application.Run "'PTSBoxPlotter.xla'!PTS_BoxWhiskerChart", _
      ActiveSheet.Range("B2:E40"), True, True, True, 1
  
End Sub

 

A more effective way to use the PTS Box and Whisker Chart Utility programmatically from your VBA project is to set a reference to the utility from within your project. From the VB Editor's Tools menu, choose References, then scroll down until you find PTSBoxCharts2000 in the list, and check the box in front of it.

Setting a reference allows you to use the utility in Early Binding mode. You have access to its public functions and constants in the Object Browser, and you have the use of IntelliSense to help you while programming.

     

 

At right the members of the PTS_BoxCharter library are shown in the Object Browser.

Below the syntax of the PTS_BoxWhiskerChart function can be examined.

Below right the BoxWhiskerChartStyle constants are enumerated.

     


 


 

     


 

Intellisense shows the syntax of the PTS_BoxWhiskerChart function as soon as you type it into a code module:


 

Intellisense displays the allowable values for the BoxWhiskerChartStyle argument, and allows you to select the desired option from the list:


 

As with the Application.Run approach, PTS_BoxWhiskerChart can be called as a function, returning the box and whisker chart to the calling procedure.

Sub TestBoxCharterFunction()
  ' VBIDE: Tools menu > References: set reference to PTS Box Charter
  Dim chtBoxWhisker As Chart
  
  Set chtBoxWhisker = PTS_BoxWhiskerChart(ActiveCell.CurrentRegion, False, True, True, BWCS_BoxWhiskerQuartile)

End Sub

PTS_BoxWhiskerChart can also be called as a sub, without returning any results to the calling procedure.

Sub TestBoxCharter()
  ' VBIDE: Tools menu > References: set reference to PTS Box Charter

  PTS_BoxWhiskerChart ActiveCell.CurrentRegion, True, True, True, BWCS_BoxWhiskerOutlier

End Sub

 


Contact Me

In the event of problems with this utility, use the following link to send me an email. While I cannot answer all email messages, I will certainly address any issues that arise. If you are reporting a problem, please describe the problem as clearly as possible, and if relevant include a copy of the data and chart.

I will also consider reasonable enhancements to the utility. I do not plan to make the utility compatible with Excel 97 or earlier or with Mac versions of Excel. The extensive data validation required to enable multiple area ranges prevents me from addressing this capability at this time.

Contact Jon about the PTS Box and Whisker Chart utility.


 

 

 

PTS Waterfall Chart Utility PTS Cluster-Stack Column Chart Utility PTS Box and Whisker Chart Utility PTS Marimekko Chart Utility PTS Dot Plot Utility PTS Cascade Chart Utility


Peltier Technical Services, Inc.

Commercial Utilities | Custom Solutions | Training | Charts and Tutorials | PTS Blog

Peltier Technical Services, Inc., Copyright © 2010. All rights reserved.
You may link to this article or portions of it on your site, but copying is prohibited without permission of Peltier Technical Services.

Microsoft Most Valuable Professional

Microsoft Most Valuable Professional

My MVP Profile