簡體   English   中英

使用rworldmap時地圖圖不完整

[英]Map plot incomplete when using rworldmap

我有一些要使用rworldmap繪制的數據。 通常,這很好。 但是我無法弄清楚為什么它說要去繪制所有數據。 特別是它並未繪制美國的數據。

我在這里有一些數據: https : //drive.google.com/file/d/1Fp7O2TRH5Blar56SqdRdcPh8Mb1Vb0pc/view?usp=sharing

我正在運行以下代碼:

mergedData = readRDS("sampleData.rds")
changeHeatMapPalette = c('#D7191D', '#FDAE61', '#FFFFBF', '#ABD9E9', '#2C7BB6')
mapData = joinCountryData2Map(mergedData, joinCode="ISO2", nameJoinColumn="country", mapResolution = "high")
mapCountryData(mapData, nameColumnToPlot="change", mapTitle="", catMethod = "diverging", colourPalette = changeHeatMapPalette, numCats = 90, borderCol = "grey70")

但是然后我得到了這張地圖: 地圖圖

注意美國沒有數據。 但這肯定在示例數據中。 而且它僅排除了一個國家,而不是美國。

108 codes from your data successfully matched countries in the map
1 codes from your data failed to match with a country code in the map
     failedCodes
[1,] "GF"       
143 codes from the map weren't represented in your data

知道我在做什么錯嗎?

問題是您以非常隨機的方式設置colourPalettenumCats參數。

從您的數據中,我們可以確切地知道我們有多少個類別,並且可以使用以下數字進行計數: length(table(mapData$change)並且您需要的顏色也是如此(如果提供的顏色較少,則mapCountData將通過警告對它們進行插值)。

話雖如此,您的問題的一種解決方案是

mapCountryData(mapData, 
  nameColumnToPlot="change", 
  mapTitle="", 
  catMethod = "diverging", 
  colourPalette = brewer.pal(library(RColorBrewer), 'RdYlBu'), 
  numCats = length(table(mapData$change)), 
  borderCol = "grey70")

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM