Mobility flows from cellphone location data

| July 11, 2020

In this post, I introduce the R package flowmapblue (http://flowmap.blue) to easily map mobility data. I show an example of a map of population flows in Spain derived from cellphone location data. These data have been obtained from the National Institute of Statistics of Spain. flowmapblue allows us to create an interactive mobility map by using just a few lines of code:

Installation

First, we need to install flowmapblue from GitHub as follows:

devtools::install_github("FlowmapBlue/flowmapblue.R")
library(flowmapblue)

Data

Then, we need to create a data frame locations with the ids, names, and coordinates of each of the locations. For example:

id,name,lat,lon
1,New York,40.713543,-74.011219
2,London,51.507425,-0.127738
3,Rio de Janeiro,-22.906241,-43.180244

And create a data frame flows with the number of people moving between origin and destination locations. For example:

origin,dest,count
1,2,42
2,1,51
3,1,50
2,3,40
1,3,22
3,2,42

Call flowmapblue()

Finally, we call the flowmapblue() function passing locations, flows and specifying several options such as clustering or animation.

flowmapblue(locations, flows, mapboxAccessToken, clustering = TRUE, darkMode = TRUE, animation = FALSE)

Final map

And that’s it! With just a few lines of code we can produce an really cool interactive mobility map. We can move the map, zoom in and out, and click the arrows to see the movement associated to each flow. We can also click the bottom right corner to open the map in full-screen mode.




comments powered by Disqus