我希望能够使用相同的shapefile自动创建一个Choropleth映射矩阵(小的倍数),但是在每个映射中映射一个不同的列值。
我创建了一个带for循环的函数,用于绘制shapefile,但由于某些原因,未显示出全色。
这似乎很简单,但显然不能按需工作。
install.packages('pacman')
pacman_pload("dplyr","rgdal","maptools","GISTools","RColorBrewer")
myGDB.gdb <- 'C:/path/myGDB.gdb'
myShapefile <- readOGR(dsn=myGDB.gdb,layer="originalLer")
###lets say this shapefile includes the same attributes as the strings in
the list below which contain integer values
##create list of variables that I want to map
maps <- c("varOne", "varTwo", "varThree", "varFour")
##create function to iterate between each variable and map them
mapem <- function(shapefile, varList){
length <- length(varList)/2
par(mar=c(1,1,2,1))
par(mfrow=c(length,length))
color=auto.shading(4,cols=brewer.pal(5,"Reds"))
for (item in varList){
choropleth(shapefile,shapefile$item,shading=color,main=item)
}
}
#call function
mapem(myShapefile,maps)
结果(使用LA ZCTA边界)...