Lightweight extension of the base R graphics system
August 9, 2025
tinyplot was developed in my own time and does not relate to my position at Amazon.
All views expressed during this talk are my own, and do not necessarily reflect the views of my employer.
Everyone’s favourite penguins…
base::plot
base::plot
NB: col = species
works here because species
is a factor.
base::plot
Q: Can you spot the error?
base::plot
A: We should have used levels(species)
, not unique(species)
.
base::plot
Ugh… our grouped coloring logic only works for the “points” components.
base::plot
Tip
In the plots that follow, plt(...)
is a shorthand alias for tinyplot(...)
.
tinyplot::plt
base::plot
But we can do a lot more than that…
tinyplot::plt
tinyplot::plt
tinyplot::plt
tinyplot::plt
tinyplot::plt
tinyplot::plt
tinyplot::plt
NB: Themes are persistent; subsequent (tiny)plots will inherit this aesthetic.
segments
to make this work?” “What about a legend..?”ggplot2
/lattice
have different APIs.)Note: Adapted from Murrell (2023).
Base graphics can produce amazing plots.
plot()
is just an (opinionated) wrapper around lower-level functions. (Koncevičius 2022)But going beyond the defaults is often (much) more work that I want to do.
tinyplot goals:
A basic version of the core routine (then called “plot2.R”) sat on my computer for a long time.
I eventually packaged it up… and invited two key collaborators:
|
"by"
keyword for other mappingsAlso works for lwd
, lty
, etc.
A "!"
suffix places the legend outside the plot area.
All tinyplot types can be passed as either a:
"p"
, "density
, "lm"
, …), ortype_points()
, type_density()
, type_lm()
, …)In general, the functional equivalents are denoted type_*()
and support direct argument passing for customization, e.g.
Note
Custom args can also be passed through plt(...)
, so long as there isn’t a top-level clash.
Themes provide a convenient way to set a preferred aesthetic for your plots.
tinytheme(...)
is persistent.Quick plotting function, which we’ll re-use for showcasing some themes on the next slide:
file
argument.alpha
and fill
arguments.x/yaxl
) and breaks (x/yaxb
).For the longer version: tinyplot pros
For the longer version: tinyplot pros
The R Core team:
My wonderful tinyplot co-maintainers:
Many other contributors, feedback providers, and a sources of inspiration.
P.S. Thanks to Ryan for letting me use this screenshot.
Just focusing on the core plot components…
(That’s about 1/3 fewer characters.)
tinyplot has zero third-party dependencies.
We’ve also kept the size of the install tarball down to a minimum (<1 MB).
Very fast to install and play with in webR / WebAssembly. (Try it!)
This is a limitation of graphics “canvas” logic. (Workarounds: Change layer order, or use x/ylim
.)
file
with plt_add
(yet)This doesn’t work:
I’m hoping to provide a native solution in the future, but workarounds for now:
plt(..., file = "myplot.png", draw = ...)
png("myplot.png"); plt(...); plt_add(...); dev.off()
I hope that I have convinced you that tinyplot covers a lot of ground.
Still, tinyplot is a relatively young project and there are some features and plot types that we don’t support (yet). Some things coming down the pike: