2

I have some data that I'd like to plot with rworldmap. Normally this works well. But I can't figure out why it's not plotting all the data when it says it's going to. Particularly it's not plotting data for the US.

I've got some data here: https://drive.google.com/file/d/1Fp7O2TRH5Blar56SqdRdcPh8Mb1Vb0pc/view?usp=sharing

And I'm running this code:

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")

But then I'm getting this map: map plot

Notice how the US has no data. But it's definitely in the sample data. And it's only excluding one country, which is not the US.

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

Any idea what I'm doing wrong?

4

1 回答 1

3

问题是您以非常随机的方式设置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")

在此处输入图像描述

于 2017-11-22T21:37:49.357 回答