The Real Powers of R Statistical Language for Map Making

There are two major — and distinct ways that the R Statistical language is a powerful tool for map making — either paired with QGIS or without.

When you should use R Statistical Language with QGIS

If you are looking for a more complicated map, one of the best ways to process and wrangle map data, Shapefiles and other geographic data is within R Studio. Much of the prep work for making a map is best down in R as you can type commands quickly, pipe and mutate data, dissolve and buffer shapes easily with R and the sf package. No mouse clicks required. It’s easy to save repeated processes in an R script.

Then once the data is ready to be mapped, export it to a geopackage or shapefile, usually which I store in the /tmp directory, as I don’t need to save the data as I can quickly re-create it with the R script. From there, I can load it into QGIS, then make the map look pretty, manipulate the styling and labeling in QGIS.

When you should use R Statistical Language Alone

R with ggplot is good for simple maps, and those you want to run off frequently with updated data, and aren’t concerned with pretty labeling. Basic, clear thematic maps where labels aren’t needed or the automatic labeling of ggrepel can be tolerated due to relatively few label overlaps. In many cases, for basic maps, ggplot makes a cleaner output, lines things up better and produces better output out of the box then what you might quickly throw together in QGIS from exported data in R.

Why I don’t use R scripting in QGIS directly

While it’s possible to do R scripting in QGIS, I would rather work in RStudio with it’s preview windows, code completion and other tools rather the use QGIS. It’s just easier to do the data wrangling and manipulation of shapefiles in RStudio, and then export to a Geopackage and load the final data in QGIS.

Leave a Reply

Your email address will not be published. Required fields are marked *