本文介绍了如何在由highcharter制作的箱线图中添加均值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用{highcharter}表示的均值上加上方框图.默认情况下,它显示:最小值,最大值,Q1,Q3和中位数.

I would like to add on the boxplot made with {highcharter} the mean.By default, it displays : min, max, Q1, Q3 and median.

非常感谢!

library(dplyr)
library(highcharter)

data(pokemon)

dat <- data_to_boxplot(pokemon, height)

highchart() %>%
  hc_xAxis(type = "category") %>%
  hc_add_series_list(dat)

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

highchart() %>%
  hc_xAxis(type = "category") %>%
  hc_add_series_list(dat)

推荐答案

您可以使用以下代码

library(dplyr)
library(highcharter)

data(pokemon)

dat <- data_to_boxplot(pokemon, height)

highchart() %>%
  hc_xAxis(type = "category") %>%
  hc_add_series_list(dat)

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

my_data <- pokemon %>%
  group_by(type_1) %>%
  summarise(Mean = mean(height))

highchart() %>%
  hc_xAxis(type = "category") %>%
  hc_add_series_list(dat) %>%
  hc_add_series(name = "Mean",
    data = my_data,
    type = "scatter",
    hcaes(x = "type_1", y = "my_data$Mean")
  )

这篇关于如何在由highcharter制作的箱线图中添加均值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 04:05