# 安装包
if (!requireNamespace("data.table", quietly = TRUE)) {
install.packages("data.table")
}
if (!requireNamespace("jsonlite", quietly = TRUE)) {
install.packages("jsonlite")
}
if (!requireNamespace("ggstatsplot", quietly = TRUE)) {
install.packages("ggstatsplot")
}
# 加载包
library(data.table)
library(jsonlite)
library(ggstatsplot)条形图(Histostats)
注记
Hiplot 网站
本页面为 Hiplot Histostats 插件的源码版本教程,您也可以使用 Hiplot 网站实现无代码绘图,更多信息请查看以下链接:
展示数据分布及统计推断。
环境配置
系统: Cross-platform (Linux/MacOS/Windows)
编程语言: R
依赖包:
data.table;jsonlite;ggstatsplot
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-28
pandoc 3.1.3 @ /usr/bin/ (via rmarkdown)
quarto 1.8.27 @ /usr/local/bin/quarto
─ Packages ───────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
data.table * 1.18.0 2025-12-24 [1] RSPM
ggstatsplot * 0.13.4 2025-12-09 [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 <- data.table::fread(jsonlite::read_json("https://hiplot.cn/ui/basic/gghistostats/data.json")$exampleData$textarea[[1]])
data <- as.data.frame(data)
# 整理数据格式
axis <- c("budget", "genre")
data[, axis[2]] <- factor(data[, axis[2]], levels = unique(data[, axis[2]]))
# 查看数据
head(data) title year
1 Lord of the Rings: The Return of the King, The 2003
2 Lord of the Rings: The Fellowship of the Ring, The 2001
3 Lord of the Rings: The Two Towers, The 2002
4 Star Wars 1977
5 Star Wars: Episode V - The Empire Strikes Back 1980
6 Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb 1964
length budget rating votes mpaa genre
1 251 94.0 9.0 103631 PG-13 Action
2 208 93.0 8.8 157608 PG-13 Action
3 223 94.0 8.8 114797 PG-13 Action
4 125 11.0 8.8 134640 PG Action
5 129 18.0 8.8 103706 PG Action
6 93 1.8 8.7 63471 PG Comedy
可视化
# 条形图
p <- grouped_gghistostats(
data = data, x = budget, grouping.var = genre,
effsize.type = "unbiased",
type = "parametric",
centrality.k = 2,
plotgrid.args = list(ncol = 2),
centrality.parameter = "solid",
centrality.line.args = list(size = 1, color = "black"),
bar.fill = "#0D47A1",
centrality.label.args = list(color = "#0D47A1", size = 3),
test.value = as.numeric(0),
normal.curve = F,
normal.curve.args = list(size = 1)
)
p
