# Install packages
if (!requireNamespace("data.table", quietly = TRUE)) {
install.packages("data.table")
}
if (!requireNamespace("jsonlite", quietly = TRUE)) {
install.packages("jsonlite")
}
if (!requireNamespace("ggplotify", quietly = TRUE)) {
install.packages("ggplotify")
}
if (!requireNamespace("beanplot", quietly = TRUE)) {
install.packages("beanplot")
}
# Load packages
library(data.table)
library(jsonlite)
library(ggplotify)
library(beanplot)Beanplot
Note
Hiplot website
This page is the tutorial for source code version of the Hiplot Beanplot plugin. You can also use the Hiplot website to achieve no code ploting. For more information please see the following link:
The beanplot is a method of visualizing the distribution characteristics.
Setup
System Requirements: Cross-platform (Linux/MacOS/Windows)
Programming language: R
Dependent packages:
data.table;jsonlite;ggplotify;beanplot
sessioninfo::session_info("attached")β Session info βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
setting value
version R version 4.5.2 (2025-10-31)
os Ubuntu 24.04.3 LTS
system x86_64, linux-gnu
ui X11
language (EN)
collate C.UTF-8
ctype C.UTF-8
tz UTC
date 2026-01-17
pandoc 3.1.3 @ /usr/bin/ (via rmarkdown)
quarto 1.8.27 @ /usr/local/bin/quarto
β Packages βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
package * version date (UTC) lib source
beanplot * 1.3.1 2022-04-09 [1] RSPM
data.table * 1.18.0 2025-12-24 [1] RSPM
ggplotify * 0.1.3 2025-09-20 [1] RSPM
jsonlite * 2.0.0 2025-03-27 [1] RSPM
[1] /home/runner/work/_temp/Library
[2] /opt/R/4.5.2/lib/R/site-library
[3] /opt/R/4.5.2/lib/R/library
* ββ Packages attached to the search path.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Data Preparation
The loaded data is data set (data on treatment outcomes of different treatment regimens).
# Load data
data <- data.table::fread(jsonlite::read_json("https://hiplot.cn/ui/basic/beanplot/data.json")$exampleData$textarea[[1]])
data <- as.data.frame(data)
# convert data structure
GroupOrder <- as.numeric(factor(data[, 2], levels = unique(data[, 2])))
data[, 2] <- paste0(data[,2], " ", as.numeric(factor(data[, 3])))
data <- cbind(data, GroupOrder)
# View data
head(data) Y X Group GroupOrder
1 4.2 low 1 treat1 1
2 11.5 low 1 treat1 1
3 7.3 low 1 treat1 1
4 5.8 low 1 treat1 1
5 6.4 low 1 treat1 1
6 10.0 low 1 treat1 1
Visualization
# Beanplot
p <- as.ggplot(function() {
beanplot(Y ~ reorder(X, GroupOrder, mean), data = data, ll = 0.04,
main = "Bean Plot", ylab = "Y", xlab = "X", side = "both",
border = NA, horizontal = F,
col = list(c("#2b70c4", "#2b70c4"),c("#e9c216", "#e9c216")),
beanlines = "mean", overallline = "mean", kernel = "gaussian")
legend("bottomright", fill = c("#2b70c4", "#e9c216"),
legend = levels(factor(data[, 3])))
})
p
