如何根据R tmap中的属性值更改多边形的边框颜色
我正在尝试使用 R 的 tmap 包创建一个地图,该包对于属性的每个值都有不同的颜色轮廓。例如,在填充多边形时,我可以简单地执行 tm_polygons(col = "variable") 来获取基于“variable”属性填充多边形的地图。我想做类似的事情,但只有边框,而不是填充。我没有找到任何好的答案,所以我希望在这里得到一些帮助!
下面是一个说明这一想法的示例:
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) + .......
我不太确定如何继续
基本上,我希望俄亥俄州、密苏里州和威斯康星州的边界具有不同的颜色,以使用 感兴趣的州
。任何帮助将不胜感激!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个可能的解决方法是将您的
POLYGONS
转换为LINESTRING
并继续使用tm_lines()
:由 reprex 包 (v2.0.1)
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)