-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ggsvg for rendering #36
base: main
Are you sure you want to change the base?
Conversation
(New flag masks still not working)
Plots flags, but justification is off a bit and produces Error in if (rasterRatio > vpRatio) { : missing value where TRUE/FALSE needed }
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) |
) | ||
grid::setChildren(x, do.call(grid::gList, flag_pics)) | ||
flag_size <- size * grid::unit(1, "mm") | ||
flag_grob <- ggsvg::svg_to_rasterGrob( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I convert the svg_text
to raw using charToRaw()
, I can skip ggsvg
and use rsvg::rsvg_nativeraster()
instead (which takes the same arguments). That's probably for the best, as I don't think Mike intends for ggsvg
to be super maintained, and rsvg
is well maintained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 }