Tuesday, 20 April 2021

How to add mean line in a boxplot made with highcharter?

I'm trying to add the average (mean) in the tooltip on the boxplot made with {highcharter} the mean. By default, it displays : min, max, Q1, Q3 and median. I already asked SO here:
How to add mean in a boxplot made with highcharter?

But now I would like to display the mean with a line ! I saw this in JS :
https://www.javaer101.com/en/article/95104988.html

And I think I'm closed with {highcharter} in my example below.

Many thanks in advance !

library(dplyr)
library(highcharter) 

data(pokemon) 

pokemon_graph <- pokemon %>% 
  group_by(type_1) %>% 
  mutate(moyenne = round(mean(height,na.rm = T)),1) %>% 
  ungroup()

dat <- data_to_boxplot(pokemon_graph, height, type_1, name = "height in meters")

highchart() %>%
  hc_xAxis(type = "category") %>%
  hc_add_series_list(dat) %>% 
  hc_tooltip(useHTML = TRUE, headerFormat = "<strong>mon graph</strong><br/>",
             pointFormat = paste0("Min: {point.low}<br/>
                                   Q1: {point.q1}<br/>
                                   Median: {point.median}<br/>
                                   Q3: {point.q3}<br/>
                                   Max: {point.high}<br/>
                                   Mean: {point.moyenne}<br/>"))

enter image description here



from How to add mean line in a boxplot made with highcharter?

No comments:

Post a Comment