type_abline | R Documentation |
These functions add straight line(s) through the current plot.
type_abline(a = 0, b = 1)
type_hline(h = 0)
type_vline(v = 0)
a , b |
the intercept (default: |
h |
y-value(s) for horizontal line(s). Numeric of length 1 or equal to the number of facets. |
v |
x-value(s) for vertical line(s). Numeric of length 1 or equal to the number of facets. |
Unlike most tinyplot types, type_abline
, type_hline
, and type_vline
cannot be called as a base plot layer. Instead they must called as a
subsequent layer via tinyplot_add
.
#
## abline
tinyplot(x = -10:10, y = rnorm(21) + -10:10, grid = TRUE)
tinyplot_add(type = "abline")
# same as...
# tinyplot_add(type = type_abline(a = 0, b = 1))
# customize by passing bespoke intercept and slope values
tinyplot_add(type = type_abline(a = -1, b = -0.5))
#
## hline and vline
# Base plot layer
tinyplot(mpg ~ hp | cyl, facet = "by", data = mtcars, ylim = c(0, 40))
# Add horizontal lines at the (default) 0 y-intercept
tinyplot_add(type = "hline", col = "grey")
# Note that group+facet aesthetics will be inherited. We can use this to
# add customized lines (here: the mean `mpg` for each `cyl` group)
tinyplot_add(type = type_hline(with(mtcars, tapply(mpg, cyl, mean))), lty = 2)
# Similar idea for vline
tinyplot_add(type = type_vline(with(mtcars, tapply(hp, cyl, mean))), lty = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.