Ryan Sleeper
Slope graphs are an engaging and effective alternative for visualizing time. In this video, Ryan will show you how to make them even better by adding vertical connecting lines – whether the x-axis is discrete or continuous.
Hi, this is Ryan, with Playfair Data TV. And in this video, I’m going to show you how to add vertical lines to slope graphs, whether the x-axis is using discrete fields or continuous fields– which I think provides a nice aesthetic to slope graphs. I explain how to make slope graphs in a little bit more detail on another video, if you want to check that out.
But just to get it started over here in Tableau Desktop, let’s assume that we’re using this line graph, that looks at average discount by region per year. To convert this line graph, which is currently a continuous line graph– I know that because this Year of Order Date pill is green– into a slope graph, the easiest way to do that is just to draw a box around all of the interior data points. Hover over any of them, and then click Exclude. And we’ve just quickly made a traditional slope graph here.
So the difference between a line graph and a slope graph is slope graphs are essentially a line graph with just two data points. We’re just really looking for the overall upward or downward movement, from one date to another– when we’re using a continuous date field, like we are currently.
So continuous slope graph at this point– this one is very easy to add the vertical lines too. Because this x-axis is continuous, we can add reference lines to it. So to get those vertical lines that connect the year 2016 data points to the year 2019 data points, simply right-click on the x-axis, and click Add Reference Line. And this one will be a minimum.
And just so we can see this updating in real-time, I’ll change the color. You have to make it one change at least for the vertical line to show up. But you can kind of already see where this is going.
Now, I’m simply formatting that first vertical line. I might do a couple of things, such as remove the label. I don’t need the minimum label on there. So I’ll click on the Label dropdown, and click None.
I might also make that line a lighter-gray color. You can kind of experiment with this. Maybe that’s a little bit too light. You can even change the weight of the line, as well as its format– so whether it’s a solid line, dashed line, or dotted line. So you can kind of experiment with that, to get the look and feel that you’re looking for. Maybe bump that one more darker and call that good.
At this point, I just need to do the same thing for the maximum line. So right-click on the axis again. Click Add Reference Line. And I want it to have no label. Change the line to be dotted. And of course, this will be the maximum instead of minimum. So that’s the biggest change there. We didn’t want to have two of the same lines, which is what I started with there.
But click Maximum, make the line dotted, and same color as the other side. And you’ve got yourself nice vertical lines, connecting the slope graph end points.
Not so easy, however, when the x-axis is discrete. So let me show you if I were to change this Year of Order Date pill to Discrete. And the reason that this is important is slope graphs, in my opinion, look a little bit nicer when the x-axis is discrete. We don’t have those irrelevant dates in between 2017 and 2018 anymore.
When this pill is blue, it’s going to draw a discrete header for each of the two years in the data set. So that’s the advantage to making slope graphs with discrete fields.
But if I go to add a reference line, that is no longer available to me. So I’m going to show you a little hack, to add those vertical lines even when your x-axis is discrete. This is an example of using Tableau in the flow.
So what I suggest you do is double-click on the Rows Shelf, and create a placeholder field. I typically do these with MIN 0.
For this one, I’m going to use the aggregation M-I-N, for min, and change this to 1. So MIN 1. That’s simply going to create the value of 1 on a second row in this view. I’m going to click Enter. And I’ll make this fit height, so that we can see what we’ve done here.
So we’ve got two measures on the Rows Shelf. What’s important about that is they each get their own Marks Shelf. And we can edit the Marks Cards independently of one another.
So I’m going to leave the slope graph on the first row as is, but navigate to the second row, and change the mark type to Bar.
We’re also not going to be coloring the second row by anything. So I’m actually going to remove Region. That’s also going to change the level of detail. Note I’ve got four regions.
So because each region equals the number 1, essentially, I’ve currently got the number 1 stacked on itself four times. When you remove that, it should make everything just add up to the number 1– because that’s what we typed as the value of our placeholder field.
The next step is to convert what we’ve got into a dual-axis combination chart. Most people learn that by clicking on the second pill, and clicking the third option from the bottom– Dual Axis.
And you might be able to start to envision how this is coming together now. But the next thing we’re going to do is fix that right axis, so that it only goes from 0 to 1. That’s going to make those vertical bars fill all the vertical space on the entire view.
To fix the axes, right-click on an axis, and click Edit Axis. And I’m going to choose Fixed, and have this run from 0 to 1, instead of 0 to 2. You should see that update in real time. Note it’s filling all the vertical space. I can now close this, and also hide that right axis. I no longer need it. So I’ll right-click on the axis, and deselect Show Header.
And now those are essentially my vertical lines. Because this MIN 1 pill still has its own Marks Shelf over here, I can still edit it independently of the left side. So one of the first things I’ll do is click on the Size Marks Card, and drag this to the left– make those vertical lines really skinny.
I might click on the Color Marks Card– make it that fourth gray from the top, like I did when those axes were continuous.
Another advantage to creating these vertical lines this way, with discrete fields, is we no longer have to use a date field. So another example you might want to use a slope graph with is, have some type of goal or benchmark on the left side, and your current performance on the right side.
Those would be drawing discrete headers, so we wouldn’t be able to use that first approach, of simply adding a reference line. But now you know the trick to adding vertical lines that connect slope graph data points, whether the x-axis is continuous or discrete.
This has been Ryan with Playfair Data TV – thanks for watching!