2017-09-13 75 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

太感謝你了! –