Reputation: 165
I am trying to recreate the following maps in R using tmap:
My questions are:
How to transform the counties with NAs from grey (which I think is the default in tmap) to diagonal stripes that is shown in the first map?
How to add a thick black border showing the whole NC state like in the second map?
Currently my R code is as follows:
tm_shape(dataframe) +
tm_polygons("variable1", id = "county", palette = "Greens", border.col = "black") +
tm_layout(panel.labels = c("ABCD"), legend.position = c("left"))
Note: The border.col = "black" colors each county border to black; however I would like to have a thicker border for the whole state.
Thank you!
Upvotes: 1
Views: 1693
Reputation: 1922
Install and load the tigris package
library(tigris)
Obtain a spatial object containing all state shapes
state <- tigris::states()
subset the SpatialPolygonsDataFrame to access the shape of NC
NC <- state[state@data$NAME == "North Carolina", ]
Obtain a spatial object containing all counties in NC
ncCounties <- counties("North Carolina", cb = TRUE)
Use the qtm(), tm_shape() and tm_borders() functions
library(tmap)
qtm(ncCounties,
fill = NULL,
fillCol = "GEOID",
borders = "#515151", )+
tm_layout(frame = FALSE)+
tm_shape(NC)+
tm_borders(lwd = 3,
col = "black")
Upvotes: 1