% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/make-figure.R
\name{hd_make}
\alias{hd_make}
\title{Build a Figure from a Specification}
\usage{
hd_make(
  spec,
  type = "column",
  opts = NULL,
  backend = "highcharter",
  use_js = TRUE,
  module = FALSE,
  ...
)
}
\arguments{
\item{spec}{A \link{hd_spec} object from \code{\link[=hd_spec]{hd_spec()}}.}

\item{type}{Character.  Geometry name - one of \code{\link[=list_geoms]{list_geoms()}}:
\code{"column"}, \code{"line"}, \code{"scatter"}, \code{"arearange"}, \code{"pie"}, or any
custom geometry added with \code{\link[=register_geom]{register_geom()}}.}

\item{opts}{A \link{hd_opts} object or \code{NULL} (uses all defaults).
Controls title, subtitle, caption, ylim, yint, flip, per-figure
colours, and highcharter theme.}

\item{backend}{Character.  Rendering engine - \code{"highcharter"} (default,
interactive) or \code{"ggplot2"} (static), or any engine added with
\code{\link[=register_backend]{register_backend()}}.}

\item{use_js}{Logical.  When \code{TRUE} (default) injects a hover-band
\code{htmlwidgets::JS()} callback via \code{point.events.mouseOver/Out}.
Tooltips, accessibility module, and all other Highcharts declarative
features are \strong{always} present.  Set \code{FALSE} for clean, no-custom-JS
widgets.  Ignored by the ggplot2 backend.}

\item{module}{Use available modules js from CDN \url{https://api.highcharts.com/highcharts/}}

\item{...}{Extra arguments forwarded to the geometry function.
Required arguments (e.g. \code{ymin}, \code{ymax} for \code{"arearange"}) \strong{must}
be supplied here.}
}
\value{
A \code{highchart} widget (highcharter backend) or \code{ggplot} object
(ggplot2 backend), invisibly wrapped so knitr/Shiny render it
automatically.
}
\description{
Renders a \link{hd_spec} and \link{hd_opts} pair using the selected backend and
geometry.  This is the central function of the package - everything else
feeds into or flows out of \code{hd_make()}.
}
\section{Workflow}{


\if{html}{\out{<div class="sourceCode r">}}\preformatted{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, backend = "ggplot2")  # static ggplot2
hd_make(spec, "line",   opts, smooth = TRUE)        # smooth spline
hd_make(spec, "pie",    opts)                       # pie / donut
}\if{html}{\out{</div>}}
}

\examples{
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))

\donttest{
# -- 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, backend = "ggplot2")
hd_make(spec, "line",    opts, backend = "ggplot2")
hd_make(spec, "scatter", opts, backend = "ggplot2")
hd_make(pie_spec, "pie", pie_opts, backend = "ggplot2")

# -- Reuse spec with different presentation --------------------------------
opts_no <- hd_opts(title = "Helseundersøkelse", subtitle = "Alle aldre")
hd_make(spec, "column", opts_no)

# -- Save outputs ----------------------------------------------------------
hd_save(hd_make(spec, "column", opts),               "column.html")
hd_save(hd_make(spec, "column", opts, backend="ggplot2"), "column.png")
}

}
\seealso{
\code{\link[=hd_spec]{hd_spec()}}, \code{\link[=hd_opts]{hd_opts()}}, \code{\link[=hd_save]{hd_save()}}, \code{\link[=hd_set_theme]{hd_set_theme()}},
\code{\link[=list_geoms]{list_geoms()}}, \code{\link[=list_backends]{list_backends()}}, \code{\link[=hd_app]{hd_app()}}
}
