A brief introduction to the library tmap in R for Geospatial Data Exploration.
Not every Data Scientist will have to decide between Python or R. I constantly see discussions around that matter, some of them annoying, some quite funny. But the truth is that there are and there will be many Data Scientists who can use both languages because they won’t need to deploy anything or bring a whole application online. They are just required to analyze some data and create a straightforward executive presentation, in the good old PowerPoint, if you will.
Recently, I needed to do that. I had to get a few data points containing Latitude and Longitude information, analyze those points and come up with a good data storytelling to detail my insights.
I gotta say that I love working with R. I think the language is easy to code and the packages are pretty well built. One of those in my treasure box is the tmap library.
One of the libraries in my treasure box is
tmap.
Thematic Map, or just tmap for shorter, is a library built in R to work with spatial data, and the thematic in its name means that we can customize and visualize the data using resources like bubbles, choropleths and layers, based on the grammar of graphics, thus resembling ggplot2, according to the library creators.
In this post, we will go over the basics to get you up to speed building maps with this great tool, giving you a solid base to create visualizations and to keep studying to create more enhanced maps.
Let’s import some libraries and get to work. Reminding that any of those that you don’t have, just use install.packages("name_of_the_library") to install it in your R Studio.
library(tidyverse) # for data manipulation
library(tmap) # for map visualization
library(sf) # for shapefile manipulation
When working with tmap, it is necessary to have data that you can plot on a map. Usually, Latitude and Longitude variables are enough. But certainly, if you have a shapefile with polygons for every region you need to…