Skip to contents

Types

The highdir framework defines four categories of specifications used to construct plots. Each category serves a distinct role in data definition, visual configuration, and geom‑level customization.

1. hd_spec()

Defines the data specifications that apply universally across all geom types. These specifications describe the input data structure and mappings required by the plotting system.

2. hd_opts()

Specifies presentation options that control chart appearance. These options are shared across multiple geoms and include settings related to layout, style, and display behavior.

3. Required Specifications

Parameters that a given geom must provide for successful rendering. These vary by geom and represent the minimum information needed for the geom to function.

4. Optional Specifications

Additional parameters that may be supplied depending on the selected geom. These extend or refine the behavior of a geom but are not mandatory.

To see the required and optionals arguments:

geom_args("line") #args in geom line
geom_args("arearange")

# or
highdir:::.get_geom("ranked_bar")$optional_args
highdir:::.get_geom("arearange")$required_args

Theming

# Set package-wide defaults for the session
hd_set_theme(
  hc_theme = "helsedirektoratet",
  colors   = c("#025169", "#7C145C", "#C68803"),
  font     = "Source Sans Pro"
)

# All subsequent hd_make() calls use these settings automatically
hd_make(spec, "column")

JavaScript injection

fig <- hd_make(spec, "column")

# Inline JS
fig <- hd_add_js(fig, code = "console.log('chart loaded');")

# From a .js file
fig <- hd_add_js(fig, file = "path/to/my-plugin.js")

# From a bundled plugin (inst/js/<name>.js)
fig <- hd_add_js(fig, plugin = "my-plugin")