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

如何修改ggpairs相关矩阵图内文本的字体样式与大小

解决ggpairs相关矩阵图内文本/数值字号与加粗问题

要调整ggpairs图内(如上三角相关系数、坐标轴文本等)的字号和加粗样式,需要针对不同元素分别设置:

1. 调整上三角相关系数的字号与加粗

上三角的相关系数属于ggally_cor图层,无法通过全局theme控制,需在wrap("cor")函数中直接添加size和face参数:

upper = list(continuous = wrap("cor", method = "pearson", size = 12, face = "bold"))

2. 修正全局主题样式设置

原代码中text = element_text(size = 16, family = "bold")有误,family用于指定字体家族(如Arial、Times),控制加粗需使用face = "bold"。同时可按需补充坐标轴标题、图例文本的样式调整。

修改后的完整代码

library(GGally)

# 创建带自定义样式的ggpairs图
Output <- ggpairs(Combined_with_MFV, 
                  columns = 2:15, 
                  aes(colour=Genotype),
                  lower = list(continuous = "smooth"),
                  # 设置上三角相关系数的字号与加粗
                  upper = list(continuous = wrap("cor", method = "pearson", size = 12, face = "bold")),
                  # 可选:调整对角线变量名称的样式
                  diag = list(continuous = wrap("barDiag", text.size = 12, text.face = "bold")))

# 自定义主题元素
Output <- Output + 
  theme(
    axis.text.x = element_text(face = "bold", size = 12), 
    axis.text.y = element_text(face = "bold", size = 12), 
    axis.title.x = element_text(face = "bold", size = 16),
    axis.title.y = element_text(face = "bold", size = 16),
    text = element_text(size = 16, face = "bold"),
    legend.text = element_text(face = "bold", size = 12)
  )

# 导出图片
tiff('Morpho.tiff', units="in", width=25, height=16, res=600, compression = 'lzw')
Output
dev.off()
getwd()

关键说明

  • 对角线的变量名称需通过diag参数内的wrap函数,用text.size和text.face调整样式。
  • 全局theme仅能控制坐标轴文本、标题、图例等通用元素的样式。

内容的提问来源于stack exchange,提问作者ORBITTING ARYABHATA

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 12:03:28