I am working with the R programming language.
I am following this tutorial over here (https://www.johnmackintosh.net/blog/2017-09-01-easy-maps-with-tmap/) and trying to produce the following maps with a new dataset:
Here is the shapefile I am using:
library(sf)
library(leaflet)
library(leafgl)
library(colourvalues)
library(leaflet.extras)
# built in shapefile
nc <- st_read(system.file("gpkg/nc.gpkg", package="sf"), quiet = TRUE) %>%
st_transform(st_crs(4326)) %>%
st_cast('POLYGON')
Next, I added several variables to this shapefile that can for plotting:
nc$var1 = rnorm(length(nc$AREA), 1000, 100)
nc$var2 = rnorm(length(nc$AREA), 1000, 100)
nc$var3 = rnorm(length(nc$AREA), 1000, 100)
nc$var4 = rnorm(length(nc$AREA), 1000, 100)
nc$var5 = rnorm(length(nc$AREA), 1000, 100)
nc$var6 = rnorm(length(nc$AREA), 1000, 100)
nc$var7 = rnorm(length(nc$AREA), 1000, 100)
nc$var8 = rnorm(length(nc$AREA), 1000, 100)
Finally, I tried to plot these maps as instructed within the tutorial:
library(tmap)
library(tmaptools)
library(viridis)
small_mult<- tm_shape(nc) +
tm_fill(col = c("var1","var2","var3","var4",
"var5","var6","var7","var8"),
palette = viridis(n = 5, direction = -1, option = "C"),
title=c("title var 1", "title var 2","title var 3","title var 4",
"title var 5","title var 6", "title var 7","title var 8"))
When I look at the output of this code - I notice the following things:
- In the tutorial, they were able to neatly make two rows of four plots each, however mine was made unevenly
- The legend appears to be intersecting with the map itself
- The font size is too small
- It appears that the maps have been "zoomed in"
In general, the maps I made seem to overall have a lower quality resolution compared to the ones from the tutorial.
Is there some options that I have missed? Is there a quick way to fix this?
Thanks!