Sometimes your plot needs a celebratory gif.
I have just finished the vizwhiz module for #RYouWithMe and to top off the series I worked out how to add an RLady Wizard to our final plot.
Just so I’ll remember for next time, here is a step by step how to…
magickpackage and load it with ggplot. Install and load the
beeprpackage too so you can have RStudio beep at you when it has finished rendering your gif (it can take a long time).
library(ggplot) library(magick) library(beepr)
raintemp %>% na.omit() %>% filter(beachbugs > 500) %>% ggplot(aes(x = rain_mm, y = beachbugs, color = temp_airport)) + geom_point() + geom_smooth() + theme_classic() + scale_colour_distiller(name = "Temp (C)", palette = "RdYlBu") + labs(title = "Mean enterococci bacteria levels at Eastern Suburbs \nbeaches as a function of rainfall and temperature", subtitle = "only day > 500", caption = "data from https://www.environment.nsw.gov.au/beachapp/report_enterococci.aspx", x = "Rainfall (mm)", y = "Mean enterococci levels") ggsave("beaches.png")
beachplot <- image_read("beaches.png") wizgif <- image_read("ladywiz.gif")
frames <- image_composite(beachplot, wizgif, offset = "+600+200")
beeprpackage and add a beep to alert you when it is done. The default sounds is a “ping” but if you like mario, try beep(sound = 8)
animation <- image_animate(frames, fps = 10) image_write(animation, "beachwiz.gif") beep()