Introducction

library(highcharter)
library(dplyr)
data(penguins, package = "palmerpenguins")

set.seed(123)

penguins <- palmerpenguins::penguins %>% 
  filter(complete.cases(.)) %>% 
  group_by(species) %>% 
  sample_n(25) %>% 
  ungroup() %>% 
  select(flipper_length_mm, bill_length_mm, species)

glimpse(penguins)
## Rows: 75
## Columns: 3
## $ flipper_length_mm <int> 184, 191, 202, 190, 201, 193, 208, 190, 192, 196,...
## $ bill_length_mm    <dbl> 34.4, 41.4, 41.4, 36.0, 41.5, 37.8, 40.8, 38.1, 3...
## $ species           <fct> Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, A...
hc <- hchart(penguins, "scatter", hcaes(x = flipper_length_mm, y = bill_length_mm, group = species)) 
hc

And:

preguins_grouped <- penguins %>% 
  group_by(species) %>% 
  summarise(flipper_length_mm_mean = mean(flipper_length_mm))

glimpse(preguins_grouped)
## Rows: 3
## Columns: 2
## $ species                <fct> Adelie, Chinstrap, Gentoo
## $ flipper_length_mm_mean <dbl> 191.16, 194.68, 216.00
hc2 <- hchart(preguins_grouped, "column", hcaes(x = species, y = flipper_length_mm_mean))
hc2

Disabled inactive state

By default, when you hover over a series all the rest are hiding using opacity. To avoidthis behaviour you can set opactiy = 1 in the series.states.inactive:

hc %>%
  hc_plotOptions(
    series = list(states = list(inactive = list(opacity = 1)))
    )

More info: https://api.highcharts.com/highcharts/plotOptions.series.states.inactive.

Example: https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/series-states-inactive-

Axis Label Custom Order

Remember hc2. If we want a new order we can give the explicit order using hc_xAxis:

lvls <- preguins_grouped %>% 
  mutate(
    species = forcats::fct_relevel(species, "Gentoo", after  = 0)
  ) %>% 
  pull(species) %>% 
  levels()

hchart(preguins_grouped, "column", hcaes(x = species, y = flipper_length_mm_mean)) %>% 
  hc_xAxis(categories = lvls)