Minimalist Maps: Making World Maps in R
R let's you do a lot of things with a lot of data. This article looks at taking various geographical data points to draw interesting, minimalist looking maps of the world.
Join the DZone community and get the full member experience.Join For Free
This week, I mentioned a series of maps, on Twitter:
Friday evening, just before leaving the office to pick-up the kids after their first week back in class, Matthew Champion (aka @matthewchampion) sent me an email, asking for more details. He wanted to know if I did produce those graphs, and if he could mention then, in a post. The truth is, I have no idea who produced those graphs, but I told him one can easily reproduce them. For instance, for the cities, in R, use
> library(maps) > data("world.cities") > plot(world.cities$lon,world.cities$lat, + pch=19,cex=.7,axes=FALSE,xlab="",ylab="")
It is possible to get a more minimalist one by plotting only cities with more than 100,000 unhabitants, e.g.,
> world.cities2 = world.cities[ + world.cities$pop>100000,] > plot(world.cities2$lon,world.cities2$lat, + pch=19,cex=.7,axes=FALSE,xlab="",ylab="")
For the airports, it was slightly more complex since on http://openflights.org/data.html#airport, 6,977 airports are mentioned. But on http://www.naturalearthdata.com/, I found another dataset with only 891 airports.
> library(maptools) > shape <- readShapePoints( + "~/data/airport/ne_10m_airports.shp") > plot(shape,pch=19,cex=.7)
On the same website, one can find a dataset for ports,
> shape <- readShapePoints( + "~/data/airport/ne_10m_ports.shp") > plot(shape,pch=19,cex=.7)
This is for graphs based on points. For those based on lines, for instance rivers, shapefiles can be downloaded from https://github.com/jjrom/hydre/tree/, and then, use
> require(maptools) > shape <- readShapeLines( + "./data/river/GRDC_687_rivers.shp") > plot(shape,col="blue")
For roads, the shapefile can be downloaded from http://www.naturalearthdata.com/
> shape <- readShapeLines( + "./data/roads/ne_10m_roads.shp") > plot(shape,lwd=.5)
Last, but not least, for lakes, we need the polygons,
> shape <- readShapePoly( + "./data/lake/ne_10m_lakes.shp") > plot(shape,col="blue",border="blue",lwd=2)
Nice, isn’t it? See See the world differently with these minimalist maps for Matthew Champion‘s post.
Published at DZone with permission of Arthur Charpentier, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.