library(maps) library(mapproj) library(sf) library(cartogram) library(ggplot2) library(dplyr) ## load world map world <- st_read("./ne_110m_admin_0_countries_lakes.shp") ## subset world <- world[world$CONTINENT == "North America" | world$CONTINENT == "South America", ] ## Add column with grand TOTAL = cultural + mixed + cultural_intangible newdata <- read.csv('./unesco_cultural_heritage_americas.csv', header=TRUE, sep=':') ## Deal with zeroes. We'll subtract the extra +1 after transform. newdata$TOTAL <- (newdata$Cultural + newdata$Mixed + newdata$Intangible) + 1 world <- world %>% left_join(newdata, by = c("NAME_EN" = "Country")) ## transform to Mercator to apply cartogram (area) transformation world <- st_transform(world, 3857) cartogram <- cartogram_cont(world, "TOTAL", itermax = 7) ## Plot (ESRI:54009 is equal-area Mollweide) svg("mapa.svg", height=18, width= 15) ggplot(cartogram) + geom_sf(aes(fill=TOTAL - 1)) + geom_sf_label(aes(label=TOTAL - 1), size=8) + coord_sf(crs = "ESRI:54009") + theme_void() + scale_fill_viridis_c( name = "UNESCO entries", breaks = c(4, 8, 16, 32), guide = guide_legend( keyheight = unit(10, units = "mm"), keywidth = unit(10, units = "mm"), label.position = "bottom", title.position = "top", nrow = 1 ) ) + labs( title = "Cultural World Heritage of America", ) + theme( text = element_text(color = "#22211d"), plot.background = element_rect(fill = "#f5f5f4", color = NA), panel.background = element_rect(fill = "#f5f5f4", color = NA), legend.background = element_rect(fill = "#f5f5f4", color = NA), plot.title = element_text( size = 40, hjust = 0.5, color = "#4e4d47", margin = margin( b = 0, t = 2, l = 2, unit = "cm" ) ), legend.position = c(0.4, 0.2), legend.text = element_text(size = 30), legend.title = element_text(size = 20) ) dev.off()