使用 R 绘制地图时向某些状态添加纹理

Adding texture to certain states when plotting maps with R

我刚开始使用 R 中的地图,但遇到了一个我无法解决的问题。 假设以下脚本:

tmp_dir = tempdir()
url_data = "http://www.sharegeo.ac.uk/download/10672/50/English%20Government%20Office%20Network%20Regions%20(GOR).zip"
zip_file = sprintf("%s/shpfile.zip", tmp_dir)
    download.file(url_data, zip_file)
unzip(zip_file, exdir = tmp_dir)
library(maptools)
gor=readShapeSpatial(sprintf('%s/Regions.shp', tmp_dir))
col=gray(gor$NUMBER/sum(gor$NUMBER))
col[5] = NA
plot(gor, col=col)

我想要一种方法,可以将纹理添加到 "col" 向量上缺少数据的状态,而不是将其保留为白色。 所以在这种情况下,例如,我正在寻找类似的东西:

如何将纹理添加到绘图的特定部分,特别是在使用地图时? 我读过 add.texture 等函数,但我无法以如此灵活的方式使用它们。

plot.SpatialPolygons()可以使用线条纹理。如果参数 density 不是 NAplot.SpatialPolygons() 使用线条纹理。

:  # (skip)
library(maptools)
col=gray(gor$NUMBER/sum(gor$NUMBER))
col[5] = NA

plot(gor, col=col)          # It's easy to use the argument `add=T`
plot(gor[5,], add=T, density=10, angle=90, col="blue")      # Left map

## Of cource, you can draw the map at once without `add=T`
col2  <- col
col2[4:5] <- c("red", "blue")

plot(gor, col=col2, density=c(rep(NA,3), 30, 10, rep(NA,4)), 
     angle=c(rep(NA,3), 0, 90, rep(NA,4)))                  # Right map