Cet article décrit comment créer un boxplot interactif dans R en utilisant le package R highcharter.
Sommaire:
Chargement des packages R réquis
# Charger les packages R requis
library(dplyr)
library(highcharter)
# Définir les options de highcharter
options(highcharter.theme = hc_theme_smpl(tooltip = list(valueDecimals = 2)))
Préparation des données
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
Boxplots horizontaux
hc <- hcboxplot(
x = ToothGrowth$len,
var = ToothGrowth$dose,
name = "Tooth Length",
color = "#2980b9"
)
hc
Boxplots verticaux
hc <- hcboxplot(
x = ToothGrowth$len,
var = ToothGrowth$dose,
outliers = FALSE,
color = "#2980b9"
) %>%
hc_chart(type = "column")
hc
Boxplots groupés
hc <- hcboxplot(
x = ToothGrowth$len,
var = ToothGrowth$dose,
var2 = ToothGrowth$supp,
outliers = FALSE
) %>%
hc_chart(type = "column")
hc
Version: English
No Comments