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

如何调整R中forestmodel包森林图的非绘图区域字体大小?

forestmodel包绘制森林图时字体大小调整问题

我用R语言的forestmodel包中forest_model函数,基于cox模型绘制森林图,其他功能均正常,但无法调整指定内容的字体大小。需要增大以下部分的字体:

  • 预测变量(Predictor)
  • 因子水平(level)
  • 置信区间数值
  • p值
    仅排除实际绘制的置信区间图形。我通过定义panels列表设置图格式,但修改该列表参数或forest_model函数参数均未改变字体大小。

代码示例

panels <- list(
  list(width = 0.01),
  list(width = 0.1, display = ~variable, fontface = "bold", heading = "Predictor"),
  list(width = 0.03),
  list(width = 0.1, display = ~level), 
  list(width = 0.01),
  list(width = 0.12, display = ~ ifelse(reference, "Reference", sprintf(
    "%0.2f (%0.2f, %0.2f)",
    trans(estimate), trans(conf.low), trans(conf.high)
  )), display_na = NA), 
  list(width = 0.05),
  list(
    width = 0.03,
    display = ~ ifelse(reference, "", format.pval(p.value, digits = 3, eps = 0.001)),
    display_na = NA, hjust = 1, heading = "P-Value"
  ), 
  list(width = 0.09), 
  list(width = 0.03, item = "vline", hjust = 0.5), 
  list(width = 0.09),
  list(
    width = 0.55, item = "forest", hjust = 0.5, heading = "Hazard ratio", linetype = "dashed",
    line_x = 0
  ),
  list(width = 0.1))

forest_model(model,
             factor_separate_line = TRUE,
             theme = theme_forest(),
             format_options = forest_model_format_options(text_size = 9, point_size = 1.5, banded = TRUE),
             exclude_infinite_cis = TRUE,
             panels
             )

已尝试的方法

  • 修改forest_model_format_options中的text_size参数
  • 在heading参数后添加heading = element_text(size = YOUR_FONT_SIZE, face = "bold")
  • 使用theme(heading = element_text(size = YOUR_FONT_SIZE, face = "bold"))
  • 使用heading = textGrob("Predictor", gp = gpar(fontsize = YOUR_FONT_SIZE))

内容的提问来源于stack exchange,提问作者Bob Johnson

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 03:16:06