| hd_make | R Documentation |
Renders a hd_spec and hd_opts pair using the selected mode and
geometry. This is the central function of the package - everything else
feeds into or flows out of hd_make().
hd_make(
spec,
type = "column",
opts = NULL,
mode = NULL,
backend = lifecycle::deprecated(),
use_js = TRUE,
module = FALSE,
...
)
spec |
A hd_spec object from |
type |
Character. Geometry name - one of |
opts |
A hd_opts object or |
mode |
Character. Rendering mode - |
backend |
Character. Rendering engine - |
use_js |
Logical. When |
module |
Use available modules js from CDN https://api.highcharts.com/highcharts/ |
... |
Extra arguments forwarded to the geometry function.
Required arguments (e.g. |
A highchart widget (highcharter backend) or ggplot object
(ggplot2 backend), invisibly wrapped so knitr/Shiny render it
automatically.
spec <- hd_spec(df, x = "age", y = "pct", group = "sex", n = "n") opts <- hd_opts(title = "Health survey", ylim = c(0, 80)) hd_make(spec, "column", opts) # highcharter (default) hd_make(spec, "column", opts, mode = "static") # static ggplot2 hd_make(spec, "line", opts, smooth = TRUE) # smooth spline hd_make(spec, "pie", opts) # pie / donut
hd_spec(), hd_opts(), hd_save(), hd_set_theme(),
list_geoms(), list_modes(), hd_app()
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)
)
spec <- hd_spec(df, x = "age", y = "pct", group = "sex", n = "n")
opts <- hd_opts(title = "Health survey results",
subtitle = "Source: FHI 2024",
ylim = c(0, 80))
# -- Interactive charts (highcharter) --------------------------------------
hd_make(spec, "column", opts)
hd_make(spec, "line", opts, smooth = TRUE)
hd_make(spec, "line", opts, smooth = FALSE, dot_size = 6)
hd_make(spec, "scatter")
# Pie chart - group is ignored; x = label, y = value
pie_df <- data.frame(category = c("A","B","C","D"),
value = c(35, 25, 20, 20))
pie_spec <- hd_spec(pie_df, x = "category", y = "value")
pie_opts <- hd_opts(title = "Share by category")
hd_make(pie_spec, "pie", pie_opts)
hd_make(pie_spec, "pie", pie_opts, inner_size = "50%") # donut
# Arearange - requires ymin + ymax in ...
df2 <- cbind(df, lo = df$pct - 5, hi = df$pct + 5)
spec2 <- hd_spec(df2, "age", "pct", group = "sex")
hd_make(spec2, "arearange", opts, ymin = "lo", ymax = "hi")
# -- Disable JS hover band -------------------------------------------------
hd_make(spec, "column", opts, use_js = FALSE)
# -- Static ggplot2 versions -----------------------------------------------
hd_make(spec, "column", opts, mode = "static")
hd_make(spec, "line", opts, mode = "static")
hd_make(spec, "scatter", opts, mode = "static")
hd_make(pie_spec, "pie", pie_opts, mode = "static")
# -- Reuse spec with different presentation --------------------------------
opts_no <- hd_opts(title = "Helseundersøkelse", subtitle = "Alle aldre")
hd_make(spec, "column", opts_no)
# -- Save outputs ----------------------------------------------------------
## Not run:
hd_save(hd_make(spec, "column", opts), "column.html")
hd_save(hd_make(spec, "column", opts, mode ="static"), "column.png")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.