我正在尝试使用 R 绘制一些土耳其语数据。
我遇到的问题是,当我将数据与形状文件(以空间多边形数据框格式)合并时,数据不再匹配正确的 pologons。我究竟做错了什么,
下面是一些可重现的代码。形状文件是一些自然地球数据(所以公共领域),我把它放在我的谷歌驱动器上,用简单的数据 excel 文件压缩。它在合并之前和之后生成 2 个标有省份名称的地块。您可以看到第二张图像“混乱”了数据,Turkey.map@data 不再匹配正确的多边形。
library(maptools)
library(readxl)
temp <- "TurkeyShapefile.zip"
URL <- "https://docs.google.com/ucid=0B0TyKM0aACIONUxfNTJwWGhrR0k&export=download"
download.file(URL,temp, mode="wb")
unzip(temp)
trtr <- readShapeSpatial("Natural_earth_admin_RMS150518_TR")
#read excel file
fname <- "TR_data.xlsx"
TRdata <- read_excel(fname, sheet = "pcnt")
Turkey.map <- trtr #create copy of trtr
#a plot of the map before the merge
plot(Turkey.map)
invisible(text(getSpPPolygonsLabptSlots(Turkey.map), labels=as.character(Turkey.map@data$Admin1Name), cex=0.5))
#merge (join data)
Turkey.map@data <- merge(Turkey.map@data,TRdata,by.x="Admin1Name",by.y="Province", all.x=TRUE)
#a plot of the map after the merge
plot(Turkey.map)
invisible(text(getSpPPolygonsLabptSlots(Turkey.map), labels=as.character(Turkey.map@data$Admin1Name), cex=0.5))
非常感谢!


