I am trying to create a map using R's tmap package that has a different color outline for each value of an attribute. When filling the polygons, for example, I can simply do tm_polygons(col = "variable") to get a map that fills the polygons based on the "variable" attribute. I wish to do a similar thing, but with just the border, not the fill. I'm not finding any good answers, so I was hoping to get some help here!
Here is an example that illustrates the idea:
library(tigris)
library(tmap)
library(tidyverse)
region_2 = states() %>% filter(REGION == 2)
states_of_interest = region_2 %>% filter(NAME %in% c("Ohio", "Missouri", "Wisconsin"))
tm_shape(region_2) + tm_polygons(col = "white") + tm_shape(states_of_interest) + .......
and I am not quite sure how to proceed
Basically, I want the borders of Ohio, Missouri, and Wisconsin to have a different color to distinguish them from one another, using the NAME attribute in states_of_interest
. Any help would be greatly appreciated!
A potential workaround is to convert your
POLYGONS
toLINESTRING
and proceed withtm_lines()
:Created on 2022-03-21 by the reprex package (v2.0.1)