Open jimjam-slam opened 1 month ago
Seeing how https://github.com/coolbutuseless/ggsvg/blob/main/R/ggsvg.R does it is v helpful, even though that package is much more complex with its CSS overrides!
This is looking pretty good now! 🥳
library(ggplot2)
devtools::load_all()
gdp <- data.frame(
name = c("us", "cn", "jp", "de", "in", "gb", "fr", "it", "ca"),
gdp = c(26854, 19374, 4410, 4309, 3740, 3160, 2924, 2170, 2090),
x = c(1, 2, 3, 1, 2, 3, 1, 2, 3),
y = c(3, 3, 3, 2, 2, 2, 1, 1, 1))
p1 <- ggplot(gdp) +
aes(x, y) +
geom_flag(aes(country = name, size = gdp),
key_glyph = draw_key_flag("jp")) +
geom_point(aes(size = gdp), colour = "#00ff0099") +
geom_text(
aes(label = toupper(name)),
nudge_y = -0.3,
size = 9,
family = "Inter",
fontface = "bold") +
geom_text(
aes(label = scales::label_dollar()(gdp)),
family = "Inter",
nudge_y = -0.45,
size = 12) +
scale_size(
range = c(1, 60),
guide = guide_none()
) +
scale_x_continuous(expand = expansion(.22)) +
scale_y_continuous(expand = expansion(.22)) +
theme_void(base_size = 28, base_family = "Inter") +
theme(
plot.title = element_text(face = "bold"),
plot.subtitle = element_text(colour = "#333333")
) +
labs(
title = "Top 10 economies by GDP",
subtitle = "In $US billions in 2023",
caption = "Source: International Monetary Fund"
) +
coord_cartesian(clip = "off")
ggsave("test.png", p1, bg = "white", width = 10, height = 13)
Avoids clipping problems with
grImport2
(see #17). Still a WIP: flags are successfully drawn, but problems to fix are:Error in if (rasterRatio > vpRatio) { : missing value where TRUE/FALSE needed }