I am creating a new figure containing a choropleth map for the Asian continent, but want to add bar charts above each country. Ideally, I would like to create something like this: https://forum.generic-mapping-tools.org/t/how-to-plot-bar-charts-on-world-map/959
I know this has been asked several times before, but the questions seem to be older and make use of packages that are not supported anymore. My approach is replicating this question.
I downloaded the shape file from Eurostat, and successfully calculated the centroids of each country within the shape file map:
library(sf)
library(tidyverse)
map <- read_sf(dsn = "C:/Users/Adrian/Desktop/PhD/Data/ne_50m_admin_0_countries",
layer = "ne_50m_admin_0_countries")
asia <- map[ map$CONTINENT %in% "Asia", ]
asia <- asia %>% mutate(centroids = st_centroid(st_geometry(.)))
asia <- asia %>% mutate(long = unlist(map(asia$centroids,1)) ,
lat = unlist(map(asia$centroids, 2)))
ggplot(data = asia) +
geom_sf() + coord_sf() +
geom_point(data = asia, aes(x = long, y = lat) ,
size = 2 )
Giving:
But I don't know how to proceed. I would like to add a bar chart on or close to each central point on the map (avoiding any overlap), with a small label denoting the country.
Something like this:
library(reshape2)
data <- as.data.frame(asia)
data <- data %>%
select(GU_A3 , POP_EST , GDP_MD)
data <- melt(data)
ggplot(data %>% filter(GU_A3 == "JPN"), aes(x=GU_A3, y=value, fill=variable)) +
geom_bar(stat='identity', position='dodge') + ggtitle("JPN") +
theme(plot.title = element_text(hjust = 0.5))
Giving:
How can I add these charts on the map? I appreciate any help.