| hd | R Documentation |
Creates an hd object that accumulates geometry and presentation layers
via +, then renders when printed. This mirrors the way ggplot2 builds
plots: data mapping is declared first; visual decisions are added
incrementally; nothing is rendered until the object hits the console (or an
explicit print() / knit call).
hd(
data = NULL,
x = NULL,
y = NULL,
group = NULL,
n = NULL,
colour = NULL,
mode = NULL,
backend = lifecycle::deprecated()
)
data |
A |
x |
Character. Column name for the x-axis variable.
Ignored when |
y |
Character. Column name for the y-axis variable.
Ignored when |
group |
Character or |
n |
Character or |
colour |
Character or |
mode |
Character. Rendering mode - |
backend |
Character. Rendering engine - |
hd() accepts either raw data columns or an existing hd_spec() object.
Passing an hd_spec is the recommended bridge for code that already
constructs specs separately (e.g. in Shiny or a reporting pipeline).
An S3 object of class "hd" with slots:
$specAn hd_spec() object.
$geomNULL until a + hd_geom_*() layer is added.
$optsAn hd_opts() object (defaults until overridden).
$modeCharacter. The resolved engine name.
hd_geom_column(), hd_geom_line(), hd_geom_arearange(),
hd_opts(), hd_make()
df <- data.frame(
age = rep(c("18-24", "25-34", "35-44", "45-54"), each = 2),
sex = rep(c("Male", "Female"), 4),
pct = c(42, 38, 55, 61, 48, 52, 60, 57),
n = c(120, 115, 200, 210, 180, 175, 160, 155)
)
# Composable style
hd(df, x = "age", y = "pct", group = "sex") +
hd_geom_column() +
hd_opts(title = "Health survey", ylim = c(0, 80))
# Pass an existing hd_spec
spec <- hd_spec(df, x = "age", y = "pct", group = "sex", n = "n")
hd(spec) +
hd_geom_line(smooth = TRUE) +
hd_opts(title = "Trend")
# Switch backend per figure
hd(df, x = "age", y = "pct", mode = "static") +
hd_geom_column() +
hd_opts(title = "Static version")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.