In this tutorial, we’ll demonstrate how to draw a Connected Scatterplot in Glimpse to visualize the changing relationship over time between two variables (gas and miles).
First, add in the data by going Data > Sample Data > driving.json from the top menu.
Then, under Visual > Mark in the Inspector panel, set the Mark type to Line.
Drag the quantitative field miles into the X encoding.
Then, drag the other quantitative field gas into the Y encoding.
To reduce the space below the plotted line, in the Inspector panel go Visual > Encoding > Scale > Domain and untick Include Zero.
To add point markers to the line, go Visual > Mark and activate Point Overlay.
Adding Year Labels
To add the year labels next to the plotted points to indicate what year they represent, follow these steps:
From the top menu go Insert > Layer > Text to add in the layer for the labels.
Drag the fields miles into the X encoding and gas into the Y encoding.
Then drag the year field into the Text encoding and change the Measure type to Nominal.
To move the labels down so that they’re not overlapping with the point markers, in the Inspector panel, go Visual > Mark > Position and in the Offset enter 12 pt for the X position.
To limit the labels so that they’re only displayed every 3 years, go Insert > Transform > Calculate from the top menu. Make sure to activate Calculate in the Outline panel under Sources.
In the Inspector panel, enter “Year labels” for the Output and in Calculate enter:
datum["Datum Index"] % 3==0 ? datum["year"] : ""
To apply this code, select the Text layer under Layers and drag the Year labels token into the Text encoding (replacing the year field).
This concludes this tutorial on drawing a Connected Scatterplot. If you want to further customize your chart, please read the documentation.