I WANT TO SHARE WITH YOU a little bit of code to make this whimsical data visualization:
Make a simple map
First we can construct a map of the lower 48 U.S. states and add a marker for each city. These data are available in the us.cities data that come with the maps package.
Add a “dunk tank”
For this example, I was feeling whimsical, so I decided to add a dunk tank, represented by a blue rectangle under the US and have the cities fall into the tank. Then I would allow the metros to rise back up based on how populous the city. New York, the most populous city would remain at the bottom, while smaller cities would get close to the top.
I did this by adding a blue rectangle below the US. Turns out the lowest latitude in the continental U.S. is just above 24, so if we extend the plot down to 0 we can add space. Then we draw a blue rectangle and drop our points there.
To do so, we need to create a couple of datasets where we overwrite latitude with new values. First we force latitude to zero, and then we allow it to vary from 0 to 24 depending on how close the population is to New York’s 8 million.
Animations with tweenr
Now we can animate.
We’ll use tweenr to create the animation. See this post about tweenr for an introduction to tweenr, and more examples here and here.