我正在使用tmap
包绘制几个多边形的边界。以下代码是一个基本示例。
library(sf)
library(tmap)
nc <- st_read(system.file("shape/nc.shp",package = "sf"))
tm_shape(nc) +
tm_borders()
这看起来不错。但是,如果更改边界线的样式,则多边形之间的边界看起来与轮廓不同。以下是一个示例。我将线型更改为点线。一些线段看起来很实心或带有许多点。
tm_shape(nc) +
tm_borders(lwd = 1,lty = "dotted")
这是另一个例子。我将线宽更改为2
,将透明度更改为0.6
。我们可以看到许多内部边界看起来比轮廓线更强。
tm_shape(nc) +
tm_borders(lwd = 2,alpha = 0.6)
我想了解为什么会发生这种情况,以及如何使所有边界和轮廓的线型通用。如果有任何提示或想法,我将不胜感激。
更新:其他绘图选项
在这里,我尝试了其他选项来模拟带有虚线边界的地图。 geom_sf
和ggspatial
可以生成点图非常相似的边界图。但是,如果我更改了sf
对象并使用base R
包中的spplot
或sp
对其进行了绘制,问题仍然存在。
geom_sf
library(ggplot2)
library(sf)
nc <- st_read(system.file("shape/nc.shp",package = "sf"))
ggplot() +
geom_sf(data = nc,linetype = "dotted",fill = "white") +
theme_bw() +
theme(panel.grid = element_blank(),axis.text = element_blank(),axis.ticks = element_blank())
ggspatial
library(ggspatial)
library(ggplot2)
library(sf)
nc <- st_read(system.file("shape/nc.shp",package = "sf"))
ggplot() +
layer_spatial(nc,axis.ticks = element_blank())
带有SP对象的基本R
library(sf)
library(sp)
nc <- st_read(system.file("shape/nc.shp",package = "sf"))
nc_sp <- as(nc,"Spatial")
plot(nc_sp,col = "white",lty = "dotted")
带有SP对象的绘图
library(sf)
library(sp)
nc <- st_read(system.file("shape/nc.shp","Spatial")
nc_sp$Z <- 1
spplot(nc_sp,zcol = "Z",col.regions = "white",lty = 3,colorkey = FALSE,par.settings = list(axis.line = list(col = 'transparent')))