Human diffusion and city influence22 Aug 2015
I recently co-authored a paper entitled “Human diffusion and city influence” in which we propose a new method to measure global and regional influence of world cities using geolocated tweets. In this paper, we select 58 out of the most populated cities of the world and analyze their influence in terms of the average radius traveled and the area covered by Twitter users visiting each of them as a function of time. In this post, I’ll show you how to make a movie displaying the “diffusion” of Twitter users from one city to the rest of the world with R. More precisely, we are going to generate and to merge into a gif file several maps of geolocated tweets of users who have been at least once in a city (Paris for example) according to the number of days since the first passage in the city.
Let’s consider a file tweet containing spatio-temporal information about tweets posted by Twitter users who have been at least once in Paris. Each line represents a tweet and each tweet has three attributes:
- Longitude (column 1);
- Latitude (column 2);
- Number of days since the first passage in Paris (column 3). All the tweets posted before the first visit in Paris have been removed.
First, we have to generate the maps of geolocated tweets of users who have been at least once in Paris according to the number of days since the first passage in the city. To do so, we plot on a map the tweet for which the number of days since the first passage in Paris is lower that d using the function map of the fields package. Then, we export the map in png in a folder “HumanDiffusion_Paris”. We repeat the process for different value of d in order to obtain a temporal evolution. Here is the code:
We can now make the movie by merging the png files into a single gif file. First install ImageMagick and then invoke convert with a system command. You can play with the parameter delay to adjust the speed.
The results is quite nice, you can observe the diffusion process, very fast during the first weeks due to the presence of non-local users coming back home. If you are interested in this work, the paper is available here .