Tinier 0.5.0

I had some time on my hands in the last few weeks while I wait to start a new job, so I went back to the tinieR package to fiddle around!

New things - petit_plot

I’d long wanted to find a way to export plots directly from R into pre-tinified image files, and although I’d found a way to do it for ggplot2 plots, doing it with base R plots and devices eluded me.

Finally I found a (slightly hacky) way of doing it by simply recording the last plot created with recordPlot, and then replaying it inside the chosen device! One of those things that seems obvious in hindsight, but it works. So, I’ve put together two new functions, petit_plot() and petit_ggplot() to save and auto-tinify plots!

You can use most of the same tinify() options as usual, including keeping the un-tiny image file too, and pass through all regular plotting options to the underlying device too. You can even use petit_plot with ragg if you have it!

You can read more in the new ‘saving plots’ package vignette here, and here’s an example of the new function in action:

library(tinieR)

p <- ggplot(data = palmerpenguins::penguins,
            aes(flipper_length_mm, body_mass_g)) +
     geom_point(aes(color = species)
     
petit_ggplot(filename = "penguins", plot = p)

I love tinkering away on this little project. Once again, I’m going to really recommend developing a package for getting to know R better. It doesn’t have to do much fancy - tinieR certainly doesn’t - but having problems to solve really gives purpose to your learning. If you want to try it, check out the R Packages book by Hadley Wickham and Jenny Bryan for a complete guide!

I hope you’ll try out tinieR for yourself - and if you encounter any issues, please let me know!

📎 Tags:

📑 Other posts in the series tinieR: