Skip to contents

Quick problem/solution recipes. Each recipe is 5-10 lines.

library(asbviz)
#> Warning: replacing previous import 'data.table::first' by 'dplyr::first' when
#> loading 'asbtools'
#> Warning: replacing previous import 'data.table::between' by 'dplyr::between'
#> when loading 'asbtools'
#> Warning: replacing previous import 'dbplyr::ident' by 'dplyr::ident' when
#> loading 'asbtools'
#> Warning: replacing previous import 'data.table::last' by 'dplyr::last' when
#> loading 'asbtools'
#> Warning: replacing previous import 'dbplyr::sql' by 'dplyr::sql' when loading
#> 'asbtools'
#> Warning: replacing previous import 'crayon::style' by 'formattable::style' when
#> loading 'asbtools'
#> Warning: replacing previous import 'crayon::reset' by 'future::reset' when
#> loading 'asbtools'
#> Warning: replacing previous import 'data.table::wday' by 'lubridate::wday' when
#> loading 'asbtools'
#> Warning: replacing previous import 'data.table::second' by 'lubridate::second'
#> when loading 'asbtools'
#> Warning: replacing previous import 'data.table::isoweek' by
#> 'lubridate::isoweek' when loading 'asbtools'
#> Warning: replacing previous import 'arrow::duration' by 'lubridate::duration'
#> when loading 'asbtools'
#> Warning: replacing previous import 'data.table::yday' by 'lubridate::yday' when
#> loading 'asbtools'
#> Warning: replacing previous import 'data.table::hour' by 'lubridate::hour' when
#> loading 'asbtools'
#> Warning: replacing previous import 'data.table::year' by 'lubridate::year' when
#> loading 'asbtools'
#> Warning: replacing previous import 'data.table::month' by 'lubridate::month'
#> when loading 'asbtools'
#> Warning: replacing previous import 'data.table::week' by 'lubridate::week' when
#> loading 'asbtools'
#> Warning: replacing previous import 'data.table::isoyear' by
#> 'lubridate::isoyear' when loading 'asbtools'
#> Warning: replacing previous import 'data.table::minute' by 'lubridate::minute'
#> when loading 'asbtools'
#> Warning: replacing previous import 'data.table::mday' by 'lubridate::mday' when
#> loading 'asbtools'
#> Warning: replacing previous import 'data.table::quarter' by
#> 'lubridate::quarter' when loading 'asbtools'
#> Warning: replacing previous import 'data.table::transpose' by
#> 'purrr::transpose' when loading 'asbtools'
#> Warning: replacing previous import 'dplyr::between' by 'rPref::between' when
#> loading 'asbtools'
#> Warning: replacing previous import 'curl::parse_date' by 'readr::parse_date'
#> when loading 'asbtools'
#> Warning: replacing previous import 'purrr::flatten_lgl' by 'rlang::flatten_lgl'
#> when loading 'asbtools'
#> Warning: replacing previous import 'purrr::splice' by 'rlang::splice' when
#> loading 'asbtools'
#> Warning: replacing previous import 'purrr::flatten_chr' by 'rlang::flatten_chr'
#> when loading 'asbtools'
#> Warning: replacing previous import 'purrr::flatten_raw' by 'rlang::flatten_raw'
#> when loading 'asbtools'
#> Warning: replacing previous import 'data.table:::=' by 'rlang:::=' when loading
#> 'asbtools'
#> Warning: replacing previous import 'arrow::string' by 'rlang::string' when
#> loading 'asbtools'
#> Warning: replacing previous import 'purrr::flatten' by 'rlang::flatten' when
#> loading 'asbtools'
#> Warning: replacing previous import 'purrr::flatten_dbl' by 'rlang::flatten_dbl'
#> when loading 'asbtools'
#> Warning: replacing previous import 'crayon::chr' by 'rlang::chr' when loading
#> 'asbtools'
#> Warning: replacing previous import 'purrr::invoke' by 'rlang::invoke' when
#> loading 'asbtools'
#> Warning: replacing previous import 'purrr::flatten_int' by 'rlang::flatten_int'
#> when loading 'asbtools'
#> Warning: replacing previous import 'readr::guess_encoding' by
#> 'rvest::guess_encoding' when loading 'asbtools'
#> Warning: replacing previous import 'DBI::fetch' by 'tidypolars::fetch' when
#> loading 'asbtools'
#> Warning: replacing previous import 'readr::col_datetime' by
#> 'vroom::col_datetime' when loading 'asbtools'
#> Warning: replacing previous import 'readr::cols' by 'vroom::cols' when loading
#> 'asbtools'
#> Warning: replacing previous import 'readr::col_time' by 'vroom::col_time' when
#> loading 'asbtools'
#> Warning: replacing previous import 'readr::cols_only' by 'vroom::cols_only'
#> when loading 'asbtools'
#> Warning: replacing previous import 'readr::cols_condense' by
#> 'vroom::cols_condense' when loading 'asbtools'
#> Warning: replacing previous import 'readr::fwf_empty' by 'vroom::fwf_empty'
#> when loading 'asbtools'
#> Warning: replacing previous import 'readr::fwf_cols' by 'vroom::fwf_cols' when
#> loading 'asbtools'
#> Warning: replacing previous import 'readr::fwf_widths' by 'vroom::fwf_widths'
#> when loading 'asbtools'
#> Warning: replacing previous import 'readr::date_names' by 'vroom::date_names'
#> when loading 'asbtools'
#> Warning: replacing previous import 'readr::col_skip' by 'vroom::col_skip' when
#> loading 'asbtools'
#> Warning: replacing previous import 'readr::col_factor' by 'vroom::col_factor'
#> when loading 'asbtools'
#> Warning: replacing previous import 'readr::date_names_lang' by
#> 'vroom::date_names_lang' when loading 'asbtools'
#> Warning: replacing previous import 'readr::col_character' by
#> 'vroom::col_character' when loading 'asbtools'
#> Warning: replacing previous import 'readr::locale' by 'vroom::locale' when
#> loading 'asbtools'
#> Warning: replacing previous import 'readr::col_date' by 'vroom::col_date' when
#> loading 'asbtools'
#> Warning: replacing previous import 'readr::col_double' by 'vroom::col_double'
#> when loading 'asbtools'
#> Warning: replacing previous import 'readr::col_integer' by 'vroom::col_integer'
#> when loading 'asbtools'
#> Warning: replacing previous import 'readr::col_number' by 'vroom::col_number'
#> when loading 'asbtools'
#> Warning: replacing previous import 'readr::col_guess' by 'vroom::col_guess'
#> when loading 'asbtools'
#> Warning: replacing previous import 'readr::as.col_spec' by 'vroom::as.col_spec'
#> when loading 'asbtools'
#> Warning: replacing previous import 'readr::fwf_positions' by
#> 'vroom::fwf_positions' when loading 'asbtools'
#> Warning: replacing previous import 'readr::problems' by 'vroom::problems' when
#> loading 'asbtools'
#> Warning: replacing previous import 'readr::date_names_langs' by
#> 'vroom::date_names_langs' when loading 'asbtools'
#> Warning: replacing previous import 'readr::spec' by 'vroom::spec' when loading
#> 'asbtools'
#> Warning: replacing previous import 'readr::col_logical' by 'vroom::col_logical'
#> when loading 'asbtools'
#> Warning: replacing previous import 'readr::output_column' by
#> 'vroom::output_column' when loading 'asbtools'
#> Warning: replacing previous import 'readr::default_locale' by
#> 'vroom::default_locale' when loading 'asbtools'
#> Warning: replacing previous import 'rlang::as_list' by 'xml2::as_list' when
#> loading 'asbtools'
#> Warning: replacing previous import 'crayon::style' by 'formattable::style' when
#> loading 'asbviz'
#> Warning: replacing previous import 'crayon::%+%' by 'ggplot2::%+%' when loading
#> 'asbviz'
#> Warning: replacing previous import 'MLmetrics::RMSE' by 'caret::RMSE' when
#> loading 'modelR2'
#> Warning: replacing previous import 'MLmetrics::MAE' by 'caret::MAE' when
#> loading 'modelR2'
#> Warning: replacing previous import 'data.table::first' by 'dplyr::first' when
#> loading 'modelR2'
#> Warning: replacing previous import 'data.table::between' by 'dplyr::between'
#> when loading 'modelR2'
#> Warning: replacing previous import 'data.table::last' by 'dplyr::last' when
#> loading 'modelR2'
#> Warning: replacing previous import 'caret::cluster' by 'future::cluster' when
#> loading 'modelR2'
#> Warning: replacing previous import 'dplyr::as_data_frame' by
#> 'igraph::as_data_frame' when loading 'modelR2'
#> Warning: replacing previous import 'future::%->%' by 'igraph::%->%' when
#> loading 'modelR2'
#> Warning: replacing previous import 'future::%<-%' by 'igraph::%<-%' when
#> loading 'modelR2'
#> Warning: replacing previous import 'dplyr::groups' by 'igraph::groups' when
#> loading 'modelR2'
#> Warning: replacing previous import 'dplyr::union' by 'igraph::union' when
#> loading 'modelR2'
#> Warning: replacing previous import 'data.table::transpose' by
#> 'purrr::transpose' when loading 'modelR2'
#> Warning: replacing previous import 'igraph::simplify' by 'purrr::simplify' when
#> loading 'modelR2'
#> Warning: replacing previous import 'caret::lift' by 'purrr::lift' when loading
#> 'modelR2'
#> Warning: replacing previous import 'kohonen::map' by 'purrr::map' when loading
#> 'modelR2'
#> Warning: replacing previous import 'igraph::compose' by 'purrr::compose' when
#> loading 'modelR2'
#> Warning: replacing previous import 'purrr::flatten_lgl' by 'rlang::flatten_lgl'
#> when loading 'modelR2'
#> Warning: replacing previous import 'purrr::splice' by 'rlang::splice' when
#> loading 'modelR2'
#> Warning: replacing previous import 'purrr::flatten_chr' by 'rlang::flatten_chr'
#> when loading 'modelR2'
#> Warning: replacing previous import 'purrr::flatten_raw' by 'rlang::flatten_raw'
#> when loading 'modelR2'
#> Warning: replacing previous import 'data.table:::=' by 'rlang:::=' when loading
#> 'modelR2'
#> Warning: replacing previous import 'igraph::is_named' by 'rlang::is_named' when
#> loading 'modelR2'
#> Warning: replacing previous import 'purrr::flatten' by 'rlang::flatten' when
#> loading 'modelR2'
#> Warning: replacing previous import 'purrr::flatten_dbl' by 'rlang::flatten_dbl'
#> when loading 'modelR2'
#> Warning: replacing previous import 'purrr::invoke' by 'rlang::invoke' when
#> loading 'modelR2'
#> Warning: replacing previous import 'purrr::flatten_int' by 'rlang::flatten_int'
#> when loading 'modelR2'
#> Warning: replacing previous import 'caret::specificity' by
#> 'rtemis::specificity' when loading 'modelR2'
#> Warning: replacing previous import 'dplyr::explain' by 'rtemis::explain' when
#> loading 'modelR2'
#> Warning: replacing previous import 'caret::sensitivity' by
#> 'rtemis::sensitivity' when loading 'modelR2'
#> Warning: replacing previous import 'recipes::tunable' by 'rtemis::tunable' when
#> loading 'modelR2'
#> Warning: replacing previous import 'caret::bag' by 'rtemis::bag' when loading
#> 'modelR2'
#> Warning: replacing previous import 'igraph::permute' by 'rtemis::permute' when
#> loading 'modelR2'
#> Warning: replacing previous import 'dplyr::summarize' by 'rtemis::summarize'
#> when loading 'modelR2'
#> Warning: replacing previous import 'janitor::clean_names' by
#> 'rtemis::clean_names' when loading 'modelR2'
#> Warning: replacing previous import 'caret::precision' by 'rtemis::precision'
#> when loading 'modelR2'
#> Warning: replacing previous import 'caret::train' by 'rtemis::train' when
#> loading 'modelR2'
#> Warning: replacing previous import 'dplyr::lag' by 'stats::lag' when loading
#> 'modelR2'
#> Warning: replacing previous import 'mice::filter' by 'stats::filter' when
#> loading 'modelR2'
#> Warning: replacing previous import 'igraph::spectrum' by 'stats::spectrum' when
#> loading 'modelR2'
#> Warning: replacing previous import 'janitor::chisq.test' by 'stats::chisq.test'
#> when loading 'modelR2'
#> Warning: replacing previous import 'recipes::step' by 'stats::step' when
#> loading 'modelR2'
#> Warning: replacing previous import 'igraph::decompose' by 'stats::decompose'
#> when loading 'modelR2'
#> Warning: replacing previous import 'janitor::fisher.test' by
#> 'stats::fisher.test' when loading 'modelR2'
#> Warning: replacing previous import 'recipes::fixed' by 'stringr::fixed' when
#> loading 'modelR2'
#> Warning: replacing previous import 'igraph::as_data_frame' by
#> 'tibble::as_data_frame' when loading 'modelR2'
#> Warning: replacing previous import 'data.table::shift' by 'tictoc::shift' when
#> loading 'modelR2'
#> Warning: replacing previous import 'rtemis::size' by 'tictoc::size' when
#> loading 'modelR2'
#> Warning: replacing previous import 'skimr::focus' by 'tidygraph::focus' when
#> loading 'modelR2'
#> Warning: replacing previous import 'igraph::groups' by 'tidygraph::groups' when
#> loading 'modelR2'
#> Warning: replacing previous import 'stats::filter' by 'tidygraph::filter' when
#> loading 'modelR2'
#> Warning: replacing previous import 'igraph::crossing' by 'tidyr::crossing' when
#> loading 'modelR2'
#> Warning: replacing previous import 'igraph::difference' by
#> 'tsibble::difference' when loading 'modelR2'
#> Warning: replacing previous import 'data.table::key' by 'tsibble::key' when
#> loading 'modelR2'
#> Warning: replacing previous import 'igraph::union' by 'tsibble::union' when
#> loading 'modelR2'
#> Warning: replacing previous import 'rtemis::kfold' by 'Laurae::kfold' when
#> loading 'modelR2'
#> Warning: replacing previous import 'magrittr::set_names' by 'purrr::set_names'
#> when loading 'asbviz'
#> Warning: replacing previous import 'purrr::flatten_lgl' by 'rlang::flatten_lgl'
#> when loading 'asbviz'
#> Warning: replacing previous import 'purrr::splice' by 'rlang::splice' when
#> loading 'asbviz'
#> Warning: replacing previous import 'purrr::flatten_chr' by 'rlang::flatten_chr'
#> when loading 'asbviz'
#> Warning: replacing previous import 'purrr::flatten_raw' by 'rlang::flatten_raw'
#> when loading 'asbviz'
#> Warning: replacing previous import 'assertthat::has_name' by 'rlang::has_name'
#> when loading 'asbviz'
#> Warning: replacing previous import 'purrr::flatten' by 'rlang::flatten' when
#> loading 'asbviz'
#> Warning: replacing previous import 'purrr::flatten_dbl' by 'rlang::flatten_dbl'
#> when loading 'asbviz'
#> Warning: replacing previous import 'crayon::chr' by 'rlang::chr' when loading
#> 'asbviz'
#> Warning: replacing previous import 'purrr::invoke' by 'rlang::invoke' when
#> loading 'asbviz'
#> Warning: replacing previous import 'purrr::flatten_int' by 'rlang::flatten_int'
#> when loading 'asbviz'
#> Warning: replacing previous import 'readr::col_factor' by 'scales::col_factor'
#> when loading 'asbviz'
#> Warning: replacing previous import 'purrr::discard' by 'scales::discard' when
#> loading 'asbviz'
#> Warning: replacing previous import 'formattable::comma' by 'scales::comma' when
#> loading 'asbviz'
#> Warning: replacing previous import 'formattable::percent' by 'scales::percent'
#> when loading 'asbviz'
#> Warning: replacing previous import 'formattable::scientific' by
#> 'scales::scientific' when loading 'asbviz'
#> Warning: replacing previous import 'magrittr::extract' by 'tidyr::extract' when
#> loading 'asbviz'
#> Warning: replacing previous import 'pals::plasma' by 'viridis::plasma' when
#> loading 'asbviz'
#> Warning: replacing previous import 'pals::inferno' by 'viridis::inferno' when
#> loading 'asbviz'
#> Warning: replacing previous import 'pals::magma' by 'viridis::magma' when
#> loading 'asbviz'
#> Warning: replacing previous import 'scales::viridis_pal' by
#> 'viridis::viridis_pal' when loading 'asbviz'
#> Warning: replacing previous import 'pals::cividis' by 'viridis::cividis' when
#> loading 'asbviz'
#> Warning: replacing previous import 'pals::turbo' by 'viridis::turbo' when
#> loading 'asbviz'
#> Warning: replacing previous import 'pals::viridis' by 'viridis::viridis' when
#> loading 'asbviz'

Formatting

1. Custom Tooltip

mtcars |>
  hc_preset("correlation", x = "wt", y = "mpg") |>
  highcharter::hc_tooltip(
    useHTML = TRUE,
    pointFormat = "<b>Weight:</b> {point.x:.1f}<br><b>MPG:</b> {point.y:.1f}"
  )
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.

2. Format Y-Axis as Currency

data.frame(product = c("A", "B", "C"), revenue = c(15000, 22000, 18000)) |>
  hc_preset("comparison", x = "product", y = "revenue") |>
  highcharter::hc_yAxis(labels = list(format = "${value:,.0f}"))

3. Format Y-Axis as Percentage

data.frame(
  date = seq(as.Date("2024-01-01"), by = "month", length.out = 6),
  rate = c(0.12, 0.15, 0.14, 0.18, 0.16, 0.20)
) |>
  hc_preset("timeseries", x = "date", y = "rate") |>
  highcharter::hc_yAxis(labels = list(format = "{value:.0%}"))

4. Rotate X-Axis Labels

data.frame(category = paste("Long Category Name", 1:10), value = sample(100, 10)) |>
  hc_preset("comparison", x = "category", y = "value") |>
  highcharter::hc_xAxis(labels = list(rotation = -45))

Styling

5. Custom Colors

iris |>
  hc_preset("correlation", x = "Sepal.Length", y = "Sepal.Width",
            group = "Species") |>
  highcharter::hc_colors(c("#2563EB", "#DC2626", "#16A34A"))
#> 
#> Using continuous color scheme pals::kovesi.linear_blue_5_95_c73
#> 
#> <colors>
#> #00014EFF #2D6CFDFF #B3FFF6FF
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.

6. Dark Mode

mtcars |>
  dplyr::count(cyl) |>
  dplyr::mutate(cyl = paste(cyl, "cyl")) |>
  hc_preset("comparison", x = "cyl", y = "n",
            theme = hc_theme_sheldon(mode = "dark"))

7. Add Subtitle and Caption

mtcars |>
  hc_preset("correlation", x = "wt", y = "mpg",
            title = "Fuel Efficiency", subtitle = "Motor Trend 1974") |>
  highcharter::hc_credits(enabled = TRUE, text = "Source: mtcars dataset")
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.

Annotations

8. Add a Horizontal Reference Line

mtcars |>
  hc_preset("correlation", x = "wt", y = "mpg") |>
  hc_add_plotline(axis = "y", value = mean(mtcars$mpg),
                  label = "Average MPG", color = "#DC2626")
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.

9. Add a Vertical Reference Line

mtcars |>
  hc_preset("correlation", x = "wt", y = "mpg") |>
  hc_add_plotline(axis = "x", value = 3.5,
                  label = "3.5 tons", color = "#2563EB")
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.

10. Add Text Annotation

mtcars |>
  hc_preset("correlation", x = "wt", y = "mpg") |>
  highcharter::hc_annotations(list(list(
    labels = list(list(
      point = list(x = 5.25, y = 10.4, xAxis = 0, yAxis = 0),
      text = "Heaviest car"
    ))
  )))
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.

Data Manipulation

11. Show Top N with “Other”

mtcars |>
  tibble::rownames_to_column("car") |>
  dplyr::slice_max(hp, n = 5) |>
  hc_preset("ranking", x = "car", y = "hp",
            title = "Top 5 Cars by Horsepower")

12. Dual Y-Axis

highcharter::highchart() |>
  highcharter::hc_yAxis_multiples(
    list(title = list(text = "Temperature")),
    list(title = list(text = "Rainfall"), opposite = TRUE)
  ) |>
  highcharter::hc_add_series(data = c(7, 6, 9, 14, 18, 21, 25, 26, 23, 18, 13, 9),
                              name = "Temperature", yAxis = 0) |>
  highcharter::hc_add_series(data = c(49, 71, 106, 129, 144, 176, 135, 148, 216, 194, 95, 54),
                              type = "column", name = "Rainfall", yAxis = 1) |>
  highcharter::hc_add_theme(hc_theme_sheldon())

13. Filter Data Before Charting

iris |>
  dplyr::filter(Species != "setosa") |>
  hc_preset("correlation", x = "Sepal.Length", y = "Sepal.Width",
            group = "Species", title = "Excluding Setosa")
#> 
#> Using continuous color scheme ggthemes::Orange-Blue Diverging
#> 
#> <colors>
#> #9E3D22FF #2B5C8AFF
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.

Interactivity

14. Enable Zoom

mtcars |>
  hc_preset("correlation", x = "wt", y = "mpg") |>
  highcharter::hc_chart(zoomType = "xy")
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.

15. Disable Legend

mtcars |>
  dplyr::count(cyl) |>
  dplyr::mutate(cyl = paste(cyl, "cyl")) |>
  hc_preset("comparison", x = "cyl", y = "n") |>
  highcharter::hc_legend(enabled = FALSE)

16. Export Button Options

mtcars |>
  hc_preset("correlation", x = "wt", y = "mpg") |>
  highcharter::hc_exporting(
    enabled = TRUE,
    buttons = list(contextButton = list(
      menuItems = c("downloadPNG", "downloadSVG", "downloadCSV")
    ))
  )
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.

Accessibility

17. Colorblind-Safe

# Default (all presets use okabe_ito)
iris |>
  hc_preset("correlation", x = "Sepal.Length", y = "Sepal.Width",
            group = "Species")
#> 
#> Using continuous color scheme grDevices::Purple-Blue
#> 
#> <colors>
#> #6B0077FF #8DA3CAFF #F1F1F1FF
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.

18. High Contrast Mode

mtcars |>
  dplyr::count(cyl) |>
  dplyr::mutate(cyl = paste(cyl, "cyl")) |>
  hc_xy(type = "column", x = "cyl", y = "n") |>
  hc_accessible(high_contrast = TRUE)

19. Custom ARIA Description

mtcars |>
  dplyr::count(cyl) |>
  dplyr::mutate(cyl = paste(cyl, "cyl")) |>
  hc_preset("comparison", x = "cyl", y = "n") |>
  highcharter::hc_chart(
    accessibility = list(
      description = "Bar chart comparing car counts across 4, 6, and 8 cylinder engines."
    )
  )

Advanced

20. Combine Preset with Custom Overrides

mtcars |>
  hc_preset("correlation", x = "wt", y = "mpg",
            title = "Custom Correlation") |>
  highcharter::hc_colors(c("#8B5CF6")) |>
  highcharter::hc_chart(zoomType = "xy") |>
  highcharter::hc_exporting(enabled = TRUE)
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
#> Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.