rworldmaps-R-不能使它具有互动性

时间:2017-09-13 21:55:43

标签: r

我的代码是:

theCountry <- c("CAN", "DEU", "ITA","USA","GBR","FRA","JPN")
# These are the ISO3 names of the countries you'd like to plot in red

malDF <- data.frame(country = c("CAN", "DEU", "ITA","USA","GBR","FRA","JPN"),
                    SixtyFivePlus = c("16.15%", "21.12%", "22.36%", "14.64%", "18.12%", "18.94%", "26.02%"))
# malDF is a data.frame with the ISO3 country names plus a variable to
# merge to the map data

malMap <- joinCountryData2Map(malDF, joinCode = "ISO3",
                              nameJoinColumn = "country")
# This will join your malDF data.frame to the country map data

mapCountryData(malMap, nameColumnToPlot="SixtyFivePlus", catMethod = "categorical",
               missingCountryCol = gray(.8), colourPalette = c("seagreen","seagreen1","seagreen2",
"seagreen3","chartreuse","chartreuse2","chartreuse4"))

identifyCountries(dF = "malDF"
                  , nameCountryColumn = "malMap"
               , nameColumnToPlot = "SixtyFivePlus"
                  , plotSelected = FALSE
                  )

它给出了这个错误: identify.default中出错(x = dF2 [[nameX]],y = dF2 [[nameY]],labels = labels,:   零长度标签&#39;指定的

我不知道在x和y中输入什么,因为我还在学习R.有人可以帮助我使地图互动,所以他们给出了向量中提到的值吗?

1 个答案:

答案 0 :(得分:1)

你已经离我很近,但是你试图勾勒malDF而不是SpatialPolygonsDataFrame。相反,您应该使用malMap对象:

identifyCountries(dF = malMap,
                  nameCountryColumn = "country",
                  nameColumnToPlot = "SixtyFivePlus"
                  , plotSelected = TRUE
)

哪个产生: enter image description here