You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在ggplot对象下方添加显著性水平图例,以及在ggforestplot森林图中实现该需求的方法咨询

如何在ggplot对象下方添加显著性水平图例,以及在ggforestplot森林图中实现该需求的方法咨询

我正在用ggforestplot()绘制多个回归模型的结果,其中部分数据是用mice()插补得到的。为了最小可复现示例(MWE),我将使用ggforestplot包自带的示例数据:

# Load packages
library(ggforestplot)
library(tidyverse)
# Use the example data of the ggforestplot() package (only a few rows of it)
df <- ggforestplot::df_linear_associations %>%
  filter(trait == "BMI") %>% slice(26:29)

在实际工作中,我先是对(部分插补后)数据的所有结果分别运行summary(pool(modelFit)),再把多个模型的结果汇总到一个数据框中。我的真实数据框结构和上述示例代码生成的结构完全一致。

示例数据展示:

# Display the example data
df

#> # A tibble: 4 × 5
#> name trait beta se pvalue
#>
#> 1 Omega-3 % BMI -0.0187 0.00906 3.90e- 2
#> 2 DHA % BMI 0.0232 0.00913 1.11e- 2
#> 3 Unsaturation BMI -0.120 0.00906 3.21e-40
#> 4 Sphingomyelins BMI 0.0608 0.00938 9.10e-11

用ggforestplot()绘制森林图非常简单:

# Create plot
ggforestplot::forestplot(
  df = df,
  name = name,
  estimate = beta,
  se = se,
  pvalue = pvalue,
  psignif = 0.002
)

问题:我该如何在这个图的下方添加一个图例,解释图中点标记所代表的显著性水平?可以参考另一个包ggstats的ggcoef_model()函数生成的图的效果:

# Load packages
library(ggstats)

# Load example data
data(tips, package = "reshape")

# Run linear model
linear_model <- lm(tip ~ size + total_bill, data = tips)

# Plot model
ggcoef_model(linear_model)

Created on 2023-09-10 with reprex v2.0.2

备注:内容来源于stack exchange,提问作者vlangen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 13:38:10