Geographic Heatmap Using Spreadsheet


Can someone please advise me the best package that I could use to create an interactive geographic heatmap, using data from the spreadsheet. The map should be color coded based on the "score" value.
Thank you

Can you elaborate on what is meant by interactive heatmap? What kind of interaction is expected?

Leaflet is usually a good first choice for shiny integration, but you are limited in available projections; Web Mercator is good on small to medium scale (country and smaller) but for truly global scale it may not be the best choice.

ggplot2 & tmap have wider range of supported projections, and may be better choices if truly global scale is required

1 Like

Thanks so much for your suggestion. I will try both ggplot2 and tmap.

When I said interaction - I meant when the mouse hovers over the specific country in the map, it should display the country name and the score. Is it possible using ggplot2 and tmap. Please let me know. Thank you again

This kind of popup and hover behaviour is indeed possible with tmap, in "view" mode.
I haven't used ggplot2 for geographic mapping myself yet, tmap works really well for me.

There's many tutorials on this available, for example:

Hovering only displays the first column of data, but with the popup (on click) data bubble, all kinds of customisation and presentation are possible.

Where tmap has limits, further features of leaflet.js are useable by calling the R leaflet library directly.


This kind of interaction will require leaflet.js - either directly via {leaflet}, or indirectly via {tmap}.

Consider something along these lines (one look at Antarctica will tell you why I don't think that leaflet is well suited for global datasets); it is nicely interactive though.

library(tmap) # for the World dataset only


chrt_src <- World %>% 
  st_transform(4326) %>%  # leaflet likes WGS84
  select(name, pop_est) %>% 
  mutate(popup_label = paste("<b>",
                             "</b><br>population estimate:",

pal <- colorBin(palette = "RdYlGn",
                bins = c(0, 10e6, 50e6, 100e6, 500e6, Inf),
                domain = chrt_src$pop_est)

leaflet(data = chrt_src) %>% 
  addProviderTiles("CartoDB.Positron") %>% 
  addPolygons(color = NA,
              fillColor = ~pal(pop_est),
              popup = ~popup_label)

1 Like

Thanks jlacko and francisbarton, for your prompt suggestions. I really appreciate it.
I will try tmap and leaflet both.