License

Licensed under a Creative Commons License

Disclaimer

All data and information provided on this site is on an as-is basis and for informational purposes only. We do neither guarantee for accuracy, completeness, suitability or validity of information on this blog nor be liable for any errors in this information or any damages arising from its use. This blog may contain links to other web sites. We do not have any control over the content contained on those sites.

Sunday, February 21, 2010

Spice up your Choropleth Maps with Excel

6 (+1) tips how to mitigate some of the disadvantages of Choropleth Maps in Microsoft Excel

We already had a couple of articles on Choropleth Maps, either using Microsoft Excel or Tableau. To be honest, I was really surprised how well these posts were received by our readers. The workbook provided for download with the first article Choropleth Maps with Excel is still in undisputed first place of all downloads here on Clearly and Simply. Thus, there was quite an avalanche of posts and comments on this topic and – despite the fact that I promised to stop posting on Choropleth Maps several times before - I announced at the end of the latest article that I am having left one ace up my sleeve regarding Choropleth Maps. Here it is and it will definitely be the last one:

Already back in September last year, Lavih sent me an email including a map template of Argentina based on Gabriel’s implementation using transparencies. With the first email Lavih asked me for an easy way to let the user change the basic fill color of the map. Over a couple of weeks we emailed back and forth and together we developed some ideas on how to improve Choropleth Map visualizations with Microsoft Excel, far beyond only changing the basic fill color.

Today’s post provides 6 (+1) tips on how to spice up your Choropleth Map visualizations using Microsoft Excel, as always including the workbooks for free download.

No information on exact values (unless you are implementing tooltips including the data)

Very limited direct comparability of the regions

Possible perception problems with regards to the size of regions (e.g. Rhode Island on a US map)

Possible misinterpretation because the size of a region may have a greater impact on the user’s visual perception than the intensity of the fill color

Requirement of real estate on a dashboard

Although you can’t do much about numbers 4 to 6, you have options to somehow mitigate at least numbers 1 to 3. The challenge of today’s post is implementing a couple of additional features helping to overcome some of the deficiencies of a Choropleth Map.

Tip 1: Increase direct comparability with an additional bar chart

The first tip addresses disadvantage #3 of the list above: the limited direct comparability of the regions. The idea is pretty simple: add an additional bar chart of all regions including the exact values (see left). Sorting the bar chart makes the comparison easier. A how-to tutorial on sorting a list using formulas can be found on Chandoo’s blog.

Highlighting the actual selected region (see also tip 3 below) with a red background helps to immediately identify the position of the selected province within the list of all regions. The highlighting is done with standard Excel conditional formatting.

Tip 2: Format values according to the selected KPI

If you want to let the user select from a list of different KPIs, you may face the following challenge: the displayed values of different KPIs may need different formatting, e.g. the values close to the bar chart (see tip 1 above). If you have some KPIs measured in absolute numbers and others measured as percentages, for instance, you need to change the format of the cells accordingly.

Here is one possible technique how to do this:

Define the desired custom format of each KPI in a cell range on the worksheet “control”

Detect the format string for the selected KPI from this list using the function INDEX based on the user selection

Add the following line to the sub “UpdateMap”: Range("myMetricsData").NumberFormat = Range("myMetricFormats").Value

“myMetricFormats” and “myMetricsData” are cell range names for the cell containing the required custom format string and the cell range with the data to be displayed / formatted.

That’s it. Each time the user selects a new KPI from the drop down list, the macro “UpdateMap” is called and automatically changes the format of the cells close to the bar chart.

Please be advised that I used a German version of Microsoft Excel to create the workbook posted for download (see below). If you are using an English version, you have to replace the commas by decimal points and vice versa in the cell range C5:C14 on the worksheet “control”.

Tip 3: Show the exact value of one selected region of the map

Overcoming the lack of information on the exact values in a Choropleth Map (limitation number 2 mentioned above) is the next issue we will address.

You have two different options to do this:

Option number one is enabling the user to click on each shape of the map and displaying a Message Box including the name of the selected province, the name of the KPI and the value. The Message Box will stay visible until the user leaves the box via the ok button or the ESC key.

To implement this little feature you have to copy the following macro to your workbook and to assign this macro to every freeform shape of your map:

After calling the sub UpdateMap, the worksheet function MATCH is used to detect and assign the number of the clicked region. Finally a Message Box is displayed including the according information of the selected province.

Option number 2 is using screen or tooltips to display the detailed information of one region when hovering over the shape with the mouse.

The basic idea is exploiting Microsoft Excel’s hyperlink functionality. Actually the links point nowhere and clicking on the shapes won’t do anything. But Excel also allows assigning screen tips to hyperlinks and this is where we will include the information (name of province, name of KPI and value). The drawback: the hyperlink does not select a region and thus we will not see the highlighting in the bar chart (see tip 1 above).

To use this option, we need some small modifications of the sub “Update Map” in our VBA:

You will notice 3 additional lines in the For Next statement. The first 2 of the new lines detect the information to be displayed using VLOOKUPs, the last line assigns the text to the screen tip of the hyperlink.

This works like a charm in Excel 2003 and earlier, but I hit a minor roadblock using this technique in Microsoft Excel 2007: hovering over a region consisting of different grouped freeform shapes (like Tierra del Fuego or Buenos Aires) does not display the screen tip. Even worse: right clicking on these grouped shapes makes Excel 2007 crash.

Tip 4: Add a color scale caption

In the previous posts on Choropleth Maps I always used a very generic color scale caption, simply indicating how to read and interpret the color grades on the map (the higher the value, the darker the color and vice versa).

Of course this is lacking context and information and we can considerably improve this by adding data ranges to the colors in the caption (see left).

The implementation is along the lines of the map itself, using rectangle shapes, assigning shape names and coloring them with VBA code. The values are calculated with rather simple formulas creating equivalent buckets.

Please be advised that there is one inaccuracy in this approach: the scale legend is discrete (20 steps of transparencies), whilst the original data uses a continuous range (i.e. assigning the exact percentage according to the data). This is a mismatch that might confuse the users. However, from my point of view, providing this color scale is definitely better than the generic caption used so far.

Tip 5: Let the user change the basic color

Agreed, this one is not really dedicated to the deficiencies of Choropleth Maps. It is rather an additional nifty interactive option to let the user change the basic color used on the dashboard. Not really necessary, but this one was the starting point of my discussion with Lavih and for the sake of completeness…

Since we are using Gabriel’s implementation with transparencies, we only need one single basic color to define the look and feel of the dashboard. If you want to provide the opportunity to conveniently switch to another look and feel, you may include the following VBA code:

' The following line is only working with Excel 2007 or higher' ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1). _' Format.Fill.ForeColor.RGB = myColor' This is the work around for Excel 2003 and earlier:' Change the color palette of the first chart fill color (number 17)' This color has to be selected as the fill color' of the bars in the bar chart

ActiveWorkbook.Colors(17) = myColorApplication.ScreenUpdating = True

EndSub

The macro “SelectColor” assigned to a button on top of the dashboard calls the color choose dialogue shown above. One single mouse click or inserting the desired RGB values allows a pretty convenient way of changing the basic color of the whole dashboard.

Tip 6: Add trend information of one region after clicking

Tip #6 is supposed to mitigate problem #1 of Choropleth Maps mentioned in the introduction (see above): No visualization of development over time.

The idea is simple: since we already have a functionality of enabling the user to select one specific region on the map (see tip 3 above), we can easily add value by displaying a trend chart for this region.

The implementation is almost as simple as the idea: Create a column chart on the worksheet "control" displaying the trend of the selected region (using IF and INDEX), use a camera object on the dashboard linking to this column chart and use some additional lines of VBA to make this camera object visible after the user selected a region and invisible again after the user left the Message Box. Here is the adopted sub SelectShape:

Last, but not least

Muchas gracias, Lavih! Many thanks for our discussion and all the ideas arising from it.

What’s next?

This was article number 10 on Choropleth Maps on this blog. Much more than I originally planned. But that’s it now. Definitely. I finally ran out of ideas regarding Choropleth Maps. Seriously.

We will come to something completely different during the next few weeks: The upcoming posts will

show a way how to export Microsoft Excel dashboards to PowerPoint with ease,

present an example of Tableau’s new fantastic service Tableau Public and

start a new category of articles here on Clearly and Simply: the development and implementation of optimization algorithms using Microsoft Excel and VBA.

I hope there is something you will be interested in.

Stay tuned.

Update on Thursday, April 19, 2012

Earlier this week, I received an interesting email from Petros Chatzipantazis, one of my few but avid readers. Based on the approaches described above, Petros developed a very clever idea how to make the hyperlink tooltip available and provide an action triggered by clicking on one of the shapes at the same time. Check out Petros’ website spreadsheet1.com for the details.

Comments

Spice up your Choropleth Maps with Excel

6 (+1) tips how to mitigate some of the disadvantages of Choropleth Maps in Microsoft Excel

We already had a couple of articles on Choropleth Maps, either using Microsoft Excel or Tableau. To be honest, I was really surprised how well these posts were received by our readers. The workbook provided for download with the first article Choropleth Maps with Excel is still in undisputed first place of all downloads here on Clearly and Simply. Thus, there was quite an avalanche of posts and comments on this topic and – despite the fact that I promised to stop posting on Choropleth Maps several times before - I announced at the end of the latest article that I am having left one ace up my sleeve regarding Choropleth Maps. Here it is and it will definitely be the last one:

Already back in September last year, Lavih sent me an email including a map template of Argentina based on Gabriel’s implementation using transparencies. With the first email Lavih asked me for an easy way to let the user change the basic fill color of the map. Over a couple of weeks we emailed back and forth and together we developed some ideas on how to improve Choropleth Map visualizations with Microsoft Excel, far beyond only changing the basic fill color.

Today’s post provides 6 (+1) tips on how to spice up your Choropleth Map visualizations using Microsoft Excel, as always including the workbooks for free download.