Day 22: highcharter

Welcome back for the 22nd day of the #packagecalendar, today we will be taking a look at the highcharter package by Joshua Kunst.

The package is available from CRAN and can be downloaded with


For the following examples, we will be using the elf dataset from earlier posts.

highcharter is a wrapper around the javascript library highcharts which allows you to create wonderful interactive charts.

highcharter lets you use a couple of different syntaxes. For now, I’ll showcase how to use the hchart() function. It has roughly the same interface as ggplot2.


hchart(elf, "scatter", hcaes(x = `Sugar Consumption`, y = `Jolliness`, group = Elf))
## Warning: `parse_quosure()` is deprecated as of rlang 0.2.0.
## Please use `parse_quo()` instead.
## This warning is displayed once per session.

Clicking on the legends will disable the points on the chart. Try it out for yourself.

Additions to this plot are handled by piping on other functions. Let’s propose we want to change the colors, we use the hc_colors() function

hchart(elf, "scatter", hcaes(x = `Sugar Consumption`, y = `Jolliness`, group = Elf)) %>%
  hc_colors(c("#9F7234", "#DA473D", "#5AA340"))
hchart(elf, "scatter", hcaes(x = `Sugar Consumption`, y = `Jolliness`, group = Elf)) %>%
  hc_colors(c("#9F7234", "#DA473D", "#5AA340")) %>%
  hc_title(text = "Buddy The Not So Jolly Elf")

Please check out the package website for many more examples.

Creating elf dataset


elf <- iris %>%
  rename(Elf = Species,
         `Sugar Consumption` = Sepal.Width,
         `Toy Making Intensity` = Sepal.Length,
         `Jolliness` = Petal.Length,
         `Reindeer Training` = Petal.Width) %>%
  mutate(Elf = factor(as.numeric(Elf), labels = c("Buddy", "Twinkle", "Holly"))) %>%
  mutate_if(is.numeric, jitter)