How to make a slope chart in Tableau

A dynamic slope chart (click to see interactive version)
A dynamic slope chart (click to see interactive version)

Slope charts are cool. They emphasise change between an end date and a start date by removing the noise in between. For a much more detailed explanation and justification, go read Andy Kirk’s homage to slope charts.

This post is going to show how to build a slope chart in Tableau. It’s not the first tutorial on this: there are others by Ben Jones and Andy Kriebel. The issue with those examples is that they all start with data that has just two time points. What happens if you have lots of time data and just want to show the start/end points?

I’m building this using the Superstore sample data.

Start with a time series.

slope start

First use a standard time series chart. In my example, I have Sales by Year for each Container. It doesn’t really matter whether you have a continuous or discrete date pill on your column shelf.

Keep only the first and last values

I want this to be a dynamic slope chart; if I filter the range of dates, the chart should continue to show only the start and end values.

To do this, I create a simple calculated field [First or Last]:

First or last

This calculation returns TRUE for the first mark on each line of each Container. Here’s what happens if I put the calculated field onto the Size shelf:

First or last on size

Show only the ends

Why put the calculation on the Size shelf? Because we need to Hide everything that isn’t the first or last values. In other words, everything that our calculation returns as False. Dropping a pill onto the size shelf reveals a legend:

Size legend

Click on False. Then right-click and choose Hide. Voila! We have our basic slope chart:

slope basic

Improving the basic slope chart

It’s easy to take this much further.

The first thing you can do is move Container from the Colour shelf to the label shelf. I like this for two reasons:

  1. It’s easier on the eye to have fewer colours
  2. The labels are right on the line so the viewer doesn’t have to move their eyes around the canvas too much to identify which line is which

You can also switch the time pill to something else if you wish. In the example below, I’ve switched to a continuous month and added a quick filter for Month:

no colour just label

We’re almost done.

I don’t like the labels, though. They’re above the lines rather than next to them and they’re only at one end.

To make space on the axis for labels alongside the lines and get the alignment correct, I need to:

  1. duplicate the SUM(Sales) pill on the Row shelf
  2. create a dual axis chart
  3. change the continuous Month to a discrete Month, as shown below:
    continuous month discrete

And we’re done (click here for an interactive version and to download my example):

final product

We now have a completed slope chart. It looks great and you can change the filters in order to clearly show the change in Container sales between any two dates.

Dual axes: nice formatting

You’ve built a nice chart using synchronised dual axes (maybe it’s a lollipop chart – as described in my previous posts!). It looks great, but you’re just left with a niggling little design flaw: those dual axis sure take up a lot of space, at the top and the bottom of your viz:

What can we do about this? The first thing I thought of was to format all the Tick Marks and Titles away from the top axis:

That’s no good – there’s a huge useless white banner of dead space at the top of the chart now.

Instead, why not just format each axis to show one of the important parts: one to show the title and one to show the tick marks? This is the end result:

Now I have the best of both worlds – the user’s not aware of any dead space, and nothing gets repeated. To format the axis, right-click anywhere on the axis on the worksheet and choose Edit axis…

On the top axis, leave the Title as it is, and show just the Minor tick marks, making sure they are the same interval as the Major tick marks on the bottom axis:

:

On the bottom axis, leave the tick marks, and delete the Title:

Job done! You’ve maximised your available space and made your users’ lives a bit easier.

Lollipop charts: part two

In my previous post, I explained how I stumbled across the lollipop chart as a way of displaying data when the values are all very high. This post reveals how I did it. Those of you who are savvy with the new features in v6 will probably have immediately guessed it was using dual axes. Here’s what my lollipop chart looks like:

What’s the trick? It revolves around duplicating your measure on the columns shelf, as follows:

You need to make sure it’s dual axis. Right-click on the second Measure pill and choose “Dual Axis” to draw each AVG(Satisfaction) on the same pane. Then right-click on one of the axes and choose “Synchronise axis” to make sure they match completely. This step is important because if you add labels to one of the measures, Tableau might stretch one axis to fit the text of the label in.

The next step is to define multiple marks. This feature might be new to you, and doesn’t exactly jump out at you in the user interface. Click on the little drop-down arrow at the right of the Marks shelf and choose “Multiple Mark Types”:

The Mark shelf now has a new row: it will say “All” and have left/right arrows. With the multiple mark feature, you can format all measures at once, or each one individually. What we need to do is set one mark to be a bar (a very thin one) and the other to be a circle, as shown below:

In my example, I have also added colour to emphasise the Customer Segment dimension. You’ll see that each Mark uses a different Dimension. While experimenting with the lollipops, I discovered that if the connecting line is the same intensity as the circle, it overwhelms the circle. By using a lighter palette on the line, things look nicer. I achieved this by duplicating the Dimension, and assigning lighter colours of the same hue to its members.

To label the min/max I turned on labels for just the Circle mark.

That’s about all you need to do. I added some shading and subtle row divider lines to highlight the different states. Finally, I formatted the axes so they were pretty much hidden.

I’ve started using this technique regularly as it engages users, and improves the data-ink ratio without sacrificing interpretation. What do you think?

The joy of six: easy error bars

Over on the forum, Hadbar asked a question about Error Bars. He asked the question back in the days of version 5, when it wasn’t straightforward to make a pleasant error bar. However, now we have the Joy of Six, we can use the new dual axis/multiple mark features to create some visually appealing error bars:

Tableau won’t calculate the error values for you, so you need those in your dataset. With this example, you need two measures:

  • Error – the magnitude of the error
  • Error lower – the lower limit of the error bar

Here’s how we build the viz. First make a regular bar chart with the relevant Dimension and Measure, as below:

To create the error bar, we build a Gantt chart on the second axis. It’s lower limit is the value of the Error lower measure, and it’s size (height) is the size of the error. Step one is to put the MIN(Error Lower) pill on the Rows shelf, and set it to use Dual Axis (click the picture to see details):

We’ve now got a dual axis graph, but there’s some way to go yet. The Error Bars need to use a different mark type, in this case a Gantt Bar. Right-click on the axis, and choose Mark Type…Gantt Bar:

Set the Size of the Gantt Bar to the size of the error. To do this, make sure the Marks shelf is showing the correct Mark. In this case, it’s MIN(Error Lower). This is a new feature in v6. In case you’ve not seen it, you can page through all the Marks:

Once you have found the correct mark, put the Error measure onto the Size shelf – that creates the Gantt bar with the height of the error. You’ll probably now notice that you have error bars, but they’re wide, and not in the right position relative to the bar. This fat bar problem is easily fixed – just slide the Size slider on the Mark shelf to be the smallest possible. That creates a nice thin line.

How to get the error bars to align correctly? Simple – right-click on the axis and choose Synchronise Axis. While you’re there, you don’t need to show the right-hand axis at all. You can’t properly hide axes in Tableau, but you can format them so they don’t appear. Right-click on the axis and choose Edit axis. Delete the title on the General tab, and in the Tick Marks tab, set the Minor and Major Tick Marks to None. Click OK and your axis has “disappeared”.

Lo and behold – you have some error bars. Play around with widths/colours and other settings to make it appear just how you want it. Coming next in the Joy Of Six series…. using parameters to create dynamic groups.