if (interactive()) {
world <- d3po::national
# Fix geometries that cross the antimeridian (date line) to avoid horizontal lines
# This affects Russia, Fiji, and other countries spanning the 180° meridian
world$geometry <- sf::st_wrap_dateline(world$geometry, options = c("WRAPDATELINE=YES"))
total_trade <- d3po::trade[
d3po::trade$year == 2023L,
c("reporter", "reporter_continent", "trade")
]
total_trade <- aggregate(trade ~ reporter, data = total_trade, FUN = sum)
colnames(total_trade) <- c("country", "trade")
world <- merge(
world,
total_trade,
by = "country",
all.x = TRUE,
all.y = FALSE
)
# my_pal <- tintin::tintin_pal(option = "The Calculus Affair")(7)
# [1] "#16A2D2" "#3C8C96" "#658C4F" "#77C08A" "#7A826A" "#A3C059" "#A78239"
my_pal <- c("#16A2D2", "#3C8C96", "#658C4F", "#77C08A", "#7A826A", "#A3C059", "#A78239")
names(my_pal) <- c(
"Africa", "Antarctica", "Asia",
"Europe", "North America", "Oceania", "South America"
)
d3po(world, width = 800, height = 600) %>%
po_geomap(daes(group = country, size = trade, color = my_pal, tooltip = country)) %>%
po_labels(title = "Trade Volume by Country in 2023")
}
Run the code above in your browser using DataLab