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

如何调整base R中pairs图对角pairs_text的字体大小

解决方法

你使用的是vcd包针对列联表的pairs()方法,你之前设置的text_panel参数用于控制非对角区域的文本面板属性,而对角区域的文本由你指定的pairs_text面板函数渲染,需要通过diag_panel_args参数将字号配置传递给对角面板才能生效。

正确代码示例:

SleepStudy_factors <- SleepStudy[sapply(SleepStudy, is.factor)] 
SleepStudy_factors <- table(SleepStudy_factors)

pairs(SleepStudy_factors, 
      diag_panel = pairs_text,
      diag_panel_args = list(cex = 0.5),
      highlighting = 2,
      direction = c("v","h"))

如果需要同时调整对角文本的其他样式,比如字体颜色、字体类型,都可以将对应参数加入diag_panel_args的列表中即可,示例:

# 同时调整对角文本字号、颜色、加粗
pairs(SleepStudy_factors, 
      diag_panel = pairs_text,
      diag_panel_args = list(cex = 0.5, col = "darkblue", font = 2),
      highlighting = 2,
      direction = c("v","h"))

内容的提问来源于stack exchange,提问作者Vijay Kalmath

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 13:45:04