I'm trying to build a world heat map and I'm stumped as to why it looked this:
My data is super simple:
Why is it not showing a normal map? Furthermore, the UK has the highest number, but it is grey?!
Please advise. Thanks
data <- data.frame(
country = c("UK", "Ghana", "USA", "Thailand", "Columbia", "Brazil"),
value = c(12, 2, 1, 2, 1, 1)
)
world <- map_data("world")
data <- merge(world, data, by.x = "region", by.y = "country")
ggplot(data, aes(x = long, y = lat, group = group)) +
geom_polygon(aes(fill = value), color = "grey") +
scale_fill_gradient(low = "blue", high = "red") +
theme_void()
I've tried various different packages but haven't been able to solve the problem.


I get a plausible result with three changes:
replace
mergewithdplyr::left_join. I suspect themergeis not preserving the proper ordering of the polygon points, leading to crisscrossing between perimeter points.add
coord_sf()to convert the coordinates to a projection, in this case using "WGS 84 / World Equidistant Cylindrical"remove the gray outline, default of which obscures most UK silhouette because its too thick.