library(highcharter)
options(highcharter.theme = hc_theme_hcrt(tooltip = list(valueDecimals = 2)))

This is a set of example to show (and remember) who to do usual needs.

Let's set charts to work with.

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

set.seed(123)

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

glimpse(penguins)

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)

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 avoid this 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)


jbkunst/highcharter documentation built on March 14, 2024, 12:52 a.m.