R语言highcharter包绘制可交互箱线图

R语言highcharter包绘制可交互箱线图

/ 93 / 0

1、导入需要的包

# 加载所需的包
library(dplyr)
library(highcharter) 

2、数据准备

data("ToothGrowth")
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
head(ToothGrowth, 4)
   len supp dose
1  4.2   VC  0.5
2 11.5   VC  0.5
3  7.3   VC  0.5
4  5.8   VC  0.5

3、绘制水平箱线图

hc <- 
  data_to_boxplot(
    ToothGrowth,
    len,
    dose,
    name = "Tooth Length", 
    color = "#2980b9",
    add_outliers = F,
  ) 

highchart()%>%
  hc_chart(inverted=T) %>%  # 垂直图转换为水平
  hc_xAxis(type = "category")%>%
  hc_add_series_list(hc)

4、绘制垂直箱线图

hc <- 
  data_to_boxplot(
    ToothGrowth,
    len,
    dose,
    name = "Tooth Length", 
    color = "#2980b9",
    add_outliers = F,
  ) 

highchart()%>%
  hc_chart(type = "column")%>%
  hc_add_series_list(hc)

5、绘制分组箱线图

hc <- 
  data_to_boxplot(
    ToothGrowth,
    len,
    dose,
    supp,
    name = "Tooth Length", 
    add_outliers = F,
  ) 

highchart()%>%
  hc_chart(type = "column")%>%
  hc_add_series_list(hc)

 

0 人收藏

发表评论