Languages tweeted around Germany: red, blue, green,
yellow, grey are for German, French, English, Dutch and
other respectively. See here for a zoomable version.
For a different purpose (sentiment analysis) I am collecting tweets around Germany anyway. In another blog entry I describe how I collected the data.
With the package openmap, it is easy to create a map of the languages tweeted. Such a map is shown on the left. However, in post-google-map times if the user sees a map, he just starts to spin his mouse wheel to zoom into the map. Lets see how one can create such a map.
Creating the mapI assume that the data is in the following format, I need coordinates and colors. See the blog how to extract the data from the json-files and do the color coding.
>head(all.data)#The lat/long data approx. 300k
long lat lang
1 4.901844 52.37762 en
2 6.255914 52.51602 nl
3 13.736128 51.04736 en
> head(cols)#The colors (appox. 300k)
 “#FF000080” “#00FF0080” “#0000FF80” …
So lets see how this works. The region of the above figure and zoom-level 4 corresponds to the path 4/8/5.png. For the next zoom level 5 one has to create the 4 files 5/16/10.png, 5/16/11.png, 5/17/10.png and 5/17/12.png. The directory corresponds to x-axis (longitude) and the file name to the y-axis (latitude), the figure below shows how the split is done.
|The tile on the left is split into 4 tiles shown on the right.|
The script below starts with the tile 4\8\5.png and recursively creates the images up to the desired zoom levels. To get the bounding boxes in terms of longitude and latitude the function tile2boundingBox is used. The maps are obtained using the map function of the OpenStreetMap package. The points have to be transformed using projectMercator(lat = sd$lat, lon = sd$lon)and can then be drawn using e.g. the points function.