Tmap:学区地图已被深灰色区域掩盖

Tmap: school district map has been masked up with dark grey areas

关于我想关注的 , I successfully plotted the school districts on a national map using the library tmap. Below is my attempt to plot the map. As you can see, this is far behind the reference(作者 Laura Bliss:Bloomberg CityLab,2015)。我猜我使用st_make_valid()时可能有问题。因此,我 运行 下面的代码来查看 Error: Shape contains invalid polygons 背后的原因(请注意,我以 Alabama (al) 为例,来自st_is_valid(..., reason = TRUE)共140行)。

al <- map[map$STATEFP == "01", ]
st_is_valid(al, reason = TRUE)

[1] "Valid Geometry"                                         
[2] "Valid Geometry"                             
[3] "Loop 2: Edge 750 has duplicate vertex with edge 811"    
[4] "Loop 40: Edge 6246 has duplicate vertex with edge 6268" 
[5] "Loop 37: Edge 9 has duplicate vertex with edge 66"      
[6] "Loop 43: Edge 19 has duplicate vertex with edge 27"     
[7] "Loop 12: Edge 680 has duplicate vertex with edge 693"   
[8] "Loop 1: Edge 752 has duplicate vertex with edge 834"    
[9] "Loop 30: Edge 142 has duplicate vertex with edge 154"   
[10] "Valid Geometry"                                         
[11] "Valid Geometry"                                         
[12] "Loop 3: Edge 1619 has duplicate vertex with edge 1641"  
[13] "Valid Geometry"                                         
[14] "Loop 3: Edge 1533 has duplicate vertex with edge 1543"  
[15] "Valid Geometry"                                         

我想知道我地图上的暗区是否因为 st_make_valid() 而出现。如果是这样,我应该如何修复这张地图以获得与我的参考相似的结果?任何 advice/suggestions/resources 解决此问题的人将不胜感激!

正如 Chris 所指出的,较暗的区域是由于您正在映射的多边形的密度。您可以使用 tmap 函数中的 lwd 参数调整边框大小。

由于多边形非常密集,并且您要根据数据填充它们,因此 lwd 参数可能会非常低。默认为 1。

示例:

library(tmap)
library(sf)

nc <-  st_read(system.file("shape/nc.shp", package="sf"))

tm_shape(nc) + tm_polygons('BIR74',lwd = 0)

tm_shape(nc) + tm_polygons('BIR74',lwd = 5)

reprex package (v2.0.1)

于 2022-04-11 创建