- Multiple views
- Case Studies:
- Halloween Candy
- Google Mobility Data
- Case Studies:
October 25 2022
Due to the pandemic, Google made data available on community mobility.
The Arizona data by county can be found on GitHub
Discuss with a classmate:
How to display many years in different facets?
We need to divide our total height by the number of subplots we will create. We will use signals to specify the space between subplots (offset), each subplot height (cellHeight) and the total height (facetHeight) of the entire plot.
signals: [ { name: "offset", value: 100}, { name: "cellHeight", value: 200}, { name: "facetHeight", update: "3 * (offset + cellHeight)"} ],
For our y scale
, we now need to adjust the range using the cellHeight
signal. Remember that the y range needs to start with the highest value first (because zero is at the top).
range: [{ signal: "cellHeight" }, 0]
We will then add a facet scale
to our scales. The idea is to facet the plot by year, to distribute the start point on the svg canvas across the different years in the data.
{ name: "facetScale", type: "band", domain: { data: "mobility", field: "year" }, range: [0, { signal: "facetHeight" }] }
We will have our marks inside a group mark again. We will have an encode
property for our group
mark where we get the y
for each facet from our facetScale
and the height for each subplot from our cellHeight
signal.
{ name: "years", type: "group", from: { facet: { data: "mobility", name: "facets", groupby: "year" } }, encode: { enter: { y: { field: "year", scale: "facetScale" }, height: { signal: "cellHeight" } } }, ... }
To add a subtitle for each plot, we need to use a text
mark outside our group mark but using the group mark name (i.e., years).
{ type: "text", from: { data: "years" }, encode: { enter: { x: { value: 200 }, y: { field: "y" }, text: { field: "datum.year" }, align: { value: "center" } } } }
We still have different counties to visualize.
Should place be filtered and have county encoded as color in the map?
We can add a HTML input element for the filtering.