#
## Basic use
tinyplot(Sepal.Width ~ Sepal.Length | Species,
facet = ~Species,
data = iris)
tinyplot_add(type = "lm") ## or : plt_add(type = "lm")
## the previous line is equivalent to (but much more convenient than)
## re-writing the full call with the new type and `add=TRUE`:
# tinyplot(Sepal.Width ~ Sepal.Length | Species,
# facet = ~Species,
# data = iris,
# type = "lm",
# add = TRUE)
## arguments relying on non-standard evaluation (e.g. `subset`) work too:
tinyplot(mpg ~ wt, data = mtcars)
tinyplot_add(subset = cyl == 4, col = "red", pch = 16)
#
## add(ing) vs draw(ing)
dat = data.frame(x = 1:3, y = 0)
## the `draw` argument layers *underneath* the main plot elements...
tinyplot(
y ~ x, data = dat, pch = 19, cex = 10,
draw = abline(h = 0, lwd = 4, col = "hotpink")
)
## ... whereas `tinyplot_add()` layers *on top*.
tinyplot(y ~ x, data = dat, pch = 19, cex = 10)
tinyplot_add(type = type_hline(0), lwd = 4, col = "hotpink")
## combine = best of both worlds? Since `draw` is generic, we can hand it
## `tinyplot_add()` directly. The line is drawn as a regular tinyplot layer,
## but underneath once more. This is especially useful for, say. flipped
## plots since correct axes inheritance is preserved. (Note that a plain
## `abline(h = 0)` is not flip-aware)
tinyplot(
y ~ x, data = dat, pch = 19, cex = 10, flip = TRUE,
draw = tinyplot_add(type = type_hline(0), lwd = 4, col = "hotpink")
)
Run the code above in your browser using DataLab