# 安装包
if (!requireNamespace("data.table", quietly = TRUE)) {
install.packages("data.table")
}
if (!requireNamespace("jsonlite", quietly = TRUE)) {
install.packages("jsonlite")
}
if (!requireNamespace("metafor", quietly = TRUE)) {
install.packages("metafor")
}
if (!requireNamespace("ggplotify", quietly = TRUE)) {
install.packages("ggplotify")
}
# 加载包
library(data.table)
library(jsonlite)
library(metafor)
library(ggplotify)漏斗图 (metafor)
注记
Hiplot 网站
本页面为 Hiplot Funnel Plot (metafor) 插件的源码版本教程,您也可以使用 Hiplot 网站实现无代码绘图,更多信息请查看以下链接:
可以用于分析 Meta 分析结果中潜在偏倚因子。
环境配置
系统: Cross-platform (Linux/MacOS/Windows)
编程语言: R
依赖包:
data.table;jsonlite;metafor;ggplotify
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
ggplotify * 0.1.3 2025-09-20 [1] RSPM
jsonlite * 2.0.0 2025-03-27 [1] RSPM
Matrix * 1.7-4 2025-08-28 [3] CRAN (R 4.5.2)
metadat * 1.4-0 2025-02-04 [1] RSPM
metafor * 4.8-0 2025-01-28 [1] RSPM
numDeriv * 2016.8-1.1 2019-06-06 [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/funnel-plot-metafor/data.json")$exampleData$textarea[[1]])
data <- as.data.frame(data)
# 整理数据格式
data2 <- escalc(ri=ri, ni=ni, data = data, measure="ZCOR")
res <- rma(yi, vi, data = data2)
# 查看数据
head(data) authors year ni ri controls design a_measure
1 Axelsson et al. 2009 109 0.187 none cross-sectional self-report
2 Axelsson et al. 2011 749 0.162 none cross-sectional self-report
3 Bruce et al. 2010 55 0.340 none prospective other
4 Christensen et al. 1999 107 0.320 none cross-sectional self-report
5 Christensen & Smith 1995 72 0.270 none prospective other
6 Cohen et al. 2004 65 0.000 none prospective other
c_measure meanage quality
1 other 22.00 1
2 NEO 53.59 1
3 NEO 43.36 2
4 other 41.70 1
5 NEO 46.39 2
6 NEO 41.20 2
可视化
# 漏斗图
p <- as.ggplot(function(){
funnel(x = res, main = "Funnel Plot (metafor)",
level = c(90, 95, 99), shade = c("white","#a90e07","#d23e0b"), refline = 0)
})
p
