The key to putting sparklines is to create two calculations that "jitter" the underlying latitude and longitude fields. These calculations will then go on the X (i.e. Columns) and Y (i.e. Rows) shelves, while the location of each sparkline (i.e. latitude and longitude) goes onto the Level of Detail shelf. The sparkline itself is a Line mark with the X axis value on the Path shelf. I also find it helpful to put the Y axis value on the Color shelf to provide a kind of labelling for the axis, but this is not strictly necessary. You can also put a third variable on the Size shelf if the sparkline is not too dense, but I have not done that in this example because there are no unused variables.
I like to create these jittered calculations in two stages. The first stage is to make two calculations called [Sparkline X] and [Sparkline Y] that compute the X and Y values for the sparkline and normalise them both to the range [-1,1]. This makes it easier to centre them on geographical points and scale them to the grid. These calculations should be aggregate calculations so that Tableau will not try to group by them, which would break the line up into a set of discrete points. In my example, the two calculations are:
- [Sparkline X] = (MAX(YEAR([date])) - 1980) / 30
- [Sparkline Y] = AVG([anomaly]) / 2
MAX (or MIN) is a convenient way to make a dimension into an aggregate without changing its value. Notice that each calculation is of the form
- (AGG - midpoint) / (half of the range)
[anomaly] varies from about -2 to +2 in my data set so the midpoint is actually 0, and I am only going to plot YEAR([date]) from about 1950 onwards, which gives a range of about 60 years centred at 1980.
The second stage is to make the actual jittered calculations using two calculations from the first stage:
- [Longitude X] = MAX([long]) + [Sparkline X]
- [Latitude Y] = MAX([lat]) + [Sparkline Y] * .75
The .75 is used to scale the Y axis to the grid used by the data. The X axis seems fine with a scaling of 1 for my grid. Again, notice that these are aggregate calculations and I have used the MAX trick on the [lat] and [long] fields. For this type of data visualisation, you should make sure that [lat] and [long] are Dimensions, not measures. Also, watch out for axis reversal - we tend to say "X and Y" and "Latitude and Longitude", but Latitude should have the Y values, not the X values! One final note: If you create the Latitude/Longitude calculations by right-clicking on your [lat]/[long] fields when they are already marked with the correct geographical role, Tableau will create the new calculation with that role already assigned.
(Incidentally, splitting up the calculations this way is an example of what we Software Engineers call "separation of concerns": the Sparkline calculations are "concerned" with the properties of the X/Y values and the Latitude calculations are "concerned" with the properties of the grid. Then if you need to adjust something, you know exactly where to go to fix it.)