Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Created February 24, 2024 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutannihilation/488c02c2274a837ef46c4288baa8bf56 to your computer and use it in GitHub Desktop.
Save yutannihilation/488c02c2274a837ef46c4288baa8bf56 to your computer and use it in GitHub Desktop.
#| dev: ragg_png
library(grid)
library(ggplot2)
# gpar everywhere to rule out an "invisible lines" issue
gp <- gpar(col = "black", fill = "transparent", lwd = 2, lty = "solid")
mm_rel <- function(...) {
unit(0.5, "npc") + unit((base::c(...) - 0.5) * 10, "mm")
}
circle_pattern <- function(r) {
pattern(
circleGrob(x = mm_rel(c(1, 3, 5) / 6), y = mm_rel(c(1, 3, 5) / 6), r = unit(r, "mm"), gp = gp),
width = unit(10, "mm"), height = unit(10, "mm"), extend = "repeat", gp = gp
)
}
d <- tempfile()
dir.create(d)
ragg::agg_png(file.path(d, "plot%03d.png"))
for (i in 1:200) {
p <- ggplot(mpg, aes(factor(cyl), fill = factor(cyl))) +
geom_bar() +
scale_fill_manual(values = lapply(c(3.3, 4.4, 5.5, 6.6) * (0.2 + 0.01 * i)^2, circle_pattern))
plot(p)
}
dev.off()
gifski::gifski(list.files(d, full.names = TRUE), delay = 0.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment