Search code examples
r

How to plot heatmap with WorldMapR (or similar package)


I'm trying to generate my own heatmap for the prevalence of H5N1 cases by country.

I try the following code:

worldplot(data = Underlag_heatmap, div = 1, ColName = "Cases",CountryName = "iso_a2", CountryNameType = "isoa2",rangeVal=c(0,100))

With the following data:

    structure(list(iso_a2 = c("AF", "BD", "KH", "CA", "CL", "CN", 
"DJ", "EC", "EG", "IN", "ID", "IQ", "LA", "MM", "NP", "NG", "PK", 
"ES", "TH", "TR", "GB", "US", "VN"), Country = c("Azerbaijan", 
"Bangladesh", "Cambodia", "Canada", "Chile", "China", "Djibouti", 
"Ecuador", "Egypt", "India", "Indonesia", "Iraq", "Lao People's Democratic Republic", 
"Myanmar", "Nepal", "Nigeria", "Pakistan", "Spain", "Thailand", 
"Turkey", "United Kingdom of Great Britain and Northern Ireland", 
"United States of America", "Viet Nam"), ...3 = c(NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA), Cases = c(8, 8, 62, 1, 1, 55, 1, 1, 359, 1, 
200, 3, 3, 1, 1, 1, 3, 2, 25, 12, 5, 1, 128), Fatalities = c(5, 
1, 41, 1, 0, 32, 0, 0, 120, 1, 168, 2, 2, 0, 1, 1, 1, 0, 17, 
4, 0, 0, 64), `Mortality rate` = c(0.625, 0.125, 0.661290322580645, 
1, 0, 0.581818181818182, 0, 0, 0.334261838440111, 1, 0.84, 0.666666666666667, 
0.666666666666667, 0, 1, 1, 0.333333333333333, 0, 0.68, 0.333333333333333, 
0, 0, 0.5)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-23L))

I get an error message complaining about a missing Mapfiller argument.

Error in `geom_sf()`:
! Problem while computing aesthetics.
ℹ Error occurred in the 1st layer.
Caused by error:
! object 'MapFiller' not found

I find this confusing since the Mapfiller argument shouldn't have anything to do with the worldplot function. In the documentation it's really only mentioned in the function for categorical variables.


Solution

  • Here is an example:

    worldplot(as.data.frame(Underlag_heatmap),
              ColName = "Cases",
              CountryName = "iso_a2",
              CountryNameType = "isoa2",
              rangeVal = c(0,100),
              annote = F)
    

    enter image description here