IN THIS POST I WANT TO EXTEND ON yesterday’s post and build an animated bivariate choropleth.
We’ll use the same data as yesterday and create a combined scatterplot with bivariate choropleth map and animate it with R.
Let’s get right to it.
We’ll follow from yesterday and load our data and do some manipulations.
In order for this to work we’ll need data from three sources:
To get this to work, we need to create three plots and combine them. First, we’ll need a legend, then we’ll need map and finally we’ll need a scatterplot. Let’s build them each up.
First the legend
Second the map
Let’s make a small multiple of the map.
Now let’s create a scatterplot to better see what’s going on with the map.
Let’s construct a small multiple version of the scatter:
Finally, using tweenr and animation we can animate it!
For smooth animations we’ll use tweenr. For a simple introduction to tweenr see this post.
Also see my earlier post about tweenr for an introduction to tweenr, and more examples here and here.
Running it gives: