2017-09-13 82 views
2

我的代码是:rworldmaps-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,: 指定的零长度'标签'

我不知道应该在x和y中放什么东西,向量中提到了吗?

回答

1

您已经接近,但您正在尝试绘制malDF这不是SpatialPolygonsDataFrame。相反,你应该使用malMap对象:

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

主要生产: enter image description here

+0

太感谢你了! –