highdir is an R package that provides a unified, mode-agnostic API for building dynamic or static figures with either highcharter, ggplot2 or other R solutions where relevant.
The package provides two complementary yet fully interoperable APIs for creating figures:
- Declarative API - define all components of a figure up front and render it in a single step.
- Layered API - incrementally compose a figure by adding layers, similar to the grammar of graphics.
Both APIs produce equivalent visual output and can target any supported mode without changes to the calling code.
With the declarative API, a figure is specified once as an hd_spec
object and can later be rendered to different modes. Mode-specific
presentation options (such as interactivity or styling tweaks) can be
supplied separately via an hc_opts object prior to rendering.
The layered API supports an exploratory, iterative workflow. Figures
are built step by step using + similar to ggplot2 style, making
this approach particularly well suited for interactive analysis and
rapid prototyping, while remaining mode-independent.
By default, highdir ships with colour palette, theme, and visual identity of The Norwegian Directorate of Health (Helsedirektoratet). To further enhance usability, a Shiny graphical user interfacef for building and previewing figures is also included as part of the package.
# Install from CRAN
install.packages("highdir")
# Install development version from GitHub
if(!require(remotes)) install.packages("remotes")
remotes::install_github("folkehelsestats/highdir")The simplest way to get started with highdir is by using the built-in Shiny app. It shows also codes to demonstrate how to use the package programmatically in R. Start the app with:
library(highdir)
hd_app()The app is also available directly through ShinyApps.io at: https://bit.ly/highdir
| Name | dynamic mode | static mode | Extra args |
|---|---|---|---|
column |
column | geom_col() |
— |
ranked_bar |
column | geom_col() |
vs, aim, char_scale, min_frac |
line |
line / spline | geom_line() |
smooth, dot_size, line_symbols |
scatter |
scatter | geom_point() |
dot_size |
arearange |
arearange | geom_ribbon() |
ymin, ymax |
pie |
pie | geom_bar(), coord_polar() |
inner_size |
stacked_column |
column | geom_bar(), facet_wrap() |
stack, stacking |
venn |
venn | eulerr::euler() |
To see complete list of extra arguments for specify geoms use
geom_args() function:
geom_args("ranked_bar")
geom_args("arearange")MIT © Kamaleri
