3

Creating Charts within a Hexmap

 3 years ago
source link: https://datavis.blog/2020/10/12/creating-charts-within-a-hexmap/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Creating Charts within a Hexmap

header.png?w=1163

If you follow Tamás Varga on Tableau Public, you’ll be familiar with his beautifully designed dashboards and visualisations. Tamás has an experimental style and I’m always intrigued to see what he’ll create next. Below are just a few examples from his portfolio.

  • school-workforce-gender-gap.png?w=1024
  • price-development-of-books-in-the-eu.png?w=1024
  • viz5-_-sexual-and-reproductive-health-and-rights.png?w=1024
  • access-to-water-and-sanitation.png?w=1024
  • flood-phenomena-in-europe.png?w=1024

For a recent #MakeoverMonday challenge, Tamás produced a tile map visualisation which had individual charts for each of the US states within it. This is a useful technique to geographically associate trends in data to the location in which those trends occur.

I asked Tamás if he would be willing to write a guest blog post on how he created this visualisation and also to give some insight into his design process and sources of inspiration. Fortunately, he agreed.

Thank you for taking the time to share your insights and process, Tamás!
With that, I’ll hand over to Tamás Varga:

Introduction

Hi Everyone,

First of all, let me thank Marc for letting me in here to share the following tutorial with you. My name is Tamás Varga and I usually spend my workdays as a business analyst \ data visualization expert helping companies to leverage the power of data to make better, data driven decisions.

When not working I’m a cheerful and a bit tired family man – father of two – and one of the regular Makeover Monday’ers of the Tableau community.

Design Process

Participating in Makeover Monday has a huge effect on my design process as well. Each week is a new challenge, therefore I developed a process that I could describe as iterative and chaotic – or experimental as I really try to not re-use ideas week by week.

From conceptual point of view – e.g. which type of chart(s) to use – I usually try to somewhat go with best practices and try to give it a minor twist, something that will make it unique and fresh. It won’t always end up as a best practice, but that’s a fair price to pay for stepping out of my comfort zone.

From technical perspective I keep things is Tableau as simple as possible and push the design part to Figma. For design ideas I go to Pinterest, browse through the Tableau Public Gallery or visit the well known dataviz blogs.

Why I call this process chaotic? Because even at the final steps a new design idea can affect the visual concept making me rework everything – even choosing a new chart type or just removing sections that I already worked a lot on.

Creating Charts within a Hexmap

In this tutorial I would like to give a detailed walkthrough – without the chaotic part – on how to create a high-level overview map of the US states – based on the foundations of a hex-tile map.

Yes, you heard it right. While the final result has not much in common with the classic hex-tile states map, it is solely based on that concept.

Datasets

First, you will need two datasets. One is obviously the Makeover Monday week 40 dataset (available here) that contains the economical output of the US states and counties from 2001 to 2018.

The other is one is simple dataset that contains the coordinates to our hex-tile map – available from this blog post (the “HexmapPlots.xlsx” link in section “1. Join Your Data”). I won’t cover the steps to join these two together, you can find a great tutorial at the aforementioned link.

This is how the join will look, using a left join on the State field:

01-join2.png

Now we have all the building blocks that we need in our hands to build our map, so let’s go.

Preparing the Calculations

We will need a few calculated fields – no surprises. Here are those:

Column Rounded
This one is relatively simple. We will have the Column and Row fields from our Hexmap Plots dataset that we use to define the position of each state on our map-like chart. If we just add these to our view as described in the hex-tile map tutorial, we will get to the following result:

02-hexmap.png?w=693

And there’s slight modification that we need to do here, this will be the Column Rounded calculated field:

round([Column],0)

Simple as that. Here’s the result:

03-hexmap.png?w=693

As you can see the points are now more closely positioned. We will use this compact view to create our visualization. OK, next one.

Index:

index()

Just the usual, NEXT!

WM GDP (Chained $):
This is a window_max calculation that we will use to create the background for each state:

window_max(SUM([GDP (Chained $)]))

This will be calculated along Year, but we will get to that point. What’s next?

% of Total:
We use this field to see the share of each state from the total US economic output.

{fixed [Year], [State]: SUM([GDP (Chained $)])}/{fixed [Year]: SUM([GDP (Chained $)])}

Not that elegant, but does the job well.

And that’s it. We have all the fields that we need, now it’s formatting, formatting, formatting most of the time.

Creating the Hexmap Worksheet

And now we arrived to the point of no return, we will start building our visualization.

  • First we add the Column Rounded and Row fields to our view. Column Rounded to Columns, Row to Rows. Let’s switch the the green pills to Dimension and then convert it to Discrete (blue pill).
  • Then we add the State field and Year to the Details pane.

This will produce the following view:

04-by-state2.png
  • Now we can add the index calculated field to columns and and compute it using Year.
05-with-index2.png
  • Add the GDP (Chained $) field to Rows (SUM as default is perfect for us) and change the mark type to Line.
06-grid2.png
  • Now add WM GDP (Chained $) to Rows and change the mark type to Area.
    • Make it dual axis with the GDP (Chained $) measure and synchronize axis.
    • Change the order of measures: WM GDP (Chained $) is the left pill, the GDP (Chained $) is the right one.
    • Let’s add the Region field to the Color pane.
    • Here we have some table calculation settings. We set the table calculation for our WINDOW_MAX calculation to be calculated like this – just select everything:
07-tc-settings-1.png?w=329

We need this setting to have our area chart as the background for our line chart for each state.

Now our viz should look like this (colors will differ, that’s for sure), we’re getting closer to the final result:

08-almost-there2.png

Now let’s make some space for our future labelling for each state. That’s when our index calculation axis comes really handy as we will set the axis range manually.

So let’s Edit Axis for index and change the range for Automatic to Fixed and set the starting value to 0 and the ending value to 55.

09-edit-axis.png?w=459
  • Now we have the right amount of space to add our labeling to chart. We will add elements to our GDP (Chained $) measure and use the capabilities of the line chart. We add the followings to the Label pane:
    • State Abbr field
    • The sum of economic output: SUM(GDP (Chained $)) – don’t forget to change the formatting of this measure to Currency Custom with Display Units set to Billions with 1 decimal places (see screenshot below). Otherwise this label would get HUGE.
    • Share of total economic output: SUM(% of Total)
    • Year on year difference: SUM(GDP (Chained $)) with table calculation:
      • Quick Table Calculation: Percent Difference
      • Compute using: Year
      • Relative to: Previous
10-format-numbers-1.png

When we have all the elements we need, we can now set and format our labelling using the following settings:

  • Alignment: Top Right
  • Marks to Label: Line Ends
  • Options: Label end of line
11-text-settings.png?w=223

Some additional trick here: in the Text options let’s align the text to the left and add two spaces before each label. This way we will have our labels neat and tidy next to our line and our charts. Using these options, we will have the information on the latest (2018) data points labelled for each state.

12-label-text-1.png

If everything went well, here’s the current state of our visualization:

13-hexmap.png

As you can see we are pretty close to finish our main chart, we only need to do some additional formatting and remove every additional lines, borders, headers etc. so let’s hide all column and row headers, axis headers and remove all lines (zero lines, gridlines, axis lines) and borders (row and column dividers).

Also we need to format our text labels and tooltips – I’ll leave up to you to format it as you like it. At the end we have a much clearer view before us:

15-hexmap.png

Create the Viz in Tooltips

The only two things we have left is to add additional insights to our tooltips to have the top 5 counties for each state and the distribution of counties based on their economic output. For this we need to create the two following worksheets:

Top 5 counties tooltip worksheet:

  • Add GDP(Chained $) as SUM to Columns
  • Add County to Rows
  • Add Region to the Color Pane
  • Add GDP (Chained $) as SUM to the Label pane
  • Switch it to Bar chart

Till this moment it’s simple, but we would only need the top 5 counties. For this we can use our index calculation that we just simply add to the Filters pane. We calculate it using County and set the range of the filter from 1 to 5. You’ll also want to sort the bars descending.

At his moment it should look like a messy stacked bar chart, but don’t worry, we will take care of it when we embed it as a tooltip.

16-tooltip1.png

County distribution tooltip worksheet:

  • Add GDP(Chained $) as SUM to Columns
  • Add Region to the Color pane (Opacity to 50%)
  • Add County to the Label pane
17-tooltip2.png

For both tooltip worksheets let’s remove lines and borders and unneeded headers to reduce visual noise.

Now we will add the tooltip worksheets to our main visualization. Open our Hex map worksheet and on the Marks pane let’s select All.

Select the Tooltip pane and select Insert in the top right corner of the pop-up window. Here you can select Sheets. From this menu you can insert the two tooltip worksheets one by one.

18-insert-sheet.png

This type of insertion should appear in your tooltip window:

<Sheet name=”Tooltip 1″ maxwidth=”300″ maxheight=”300″ filter=”<All Fields>”>

Here you can modify the size of the chart that will appear in the tooltip by changing the maxwidth and maxheight parameters. (I will also leave this up to your design preferences.)

What‘s more important is to change the filter parameter to filter on State and Year:

<Sheet name=”Tooltip 1″ maxwidth=”300″ maxheight=”200″ filter=”<Year>,<State>”>

This way we tell our tooltip chart how to filter data when we hover over a data point in our map chart.

Repeat the same to insert the Tooltip 2 sheet and add some additional fields and text above these and you should have a tooltip like this:

19-vitt.png

Here you can find a more detailed tutorial on how to build a Viz in Tooltip (chart in the tooltip):
https://help.tableau.com/current/pro/desktop/en-us/viz_in_tooltip.htm

…and this should be it! You can now continue working on the final dashboard and formatting or add additional content to the tooltips or the chart itself, but now you have the high-level overview map chart.

Final Dashboard

Below is an image of the final dashboard. Click the image to open an interactive version on Tableau Public:

20-final-dashboard.png

If you are interested in my work or if you would like to contact me, you can find me here:

Tableau Public | Twitter | LinkedIn

Thank you and have a great day!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK