首页 > 解决方案 > 在 R 中调整从标签到表格的距离 grid.arrange

问题描述

我找不到如何在 grid.arrange 中调整标签到表格的距离:

distances_lsit = c(25,50,75,100) 
category_lsit = 0:5 
damage_table = matrix(NA, nrow=length(distances_lsit), ncol=length(category_lsit))
damage_table[1,] = c(10,25,50,75,100,100)
damage_table[2,] = c(5,10,25,50,75,100)
damage_table[3,] = c(2.5,5,10,25,50,75)
damage_table[4,] = c(0,2.5,5,10,25,50)
rownames(damage_table) = distances_lsit
colnames(damage_table) = category_lsit
table_scale = tableGrob(damage_table)

grid.arrange(table_scale, top = "Label 1", left = "Label 2")

它产生如下表: 在此处输入图像描述

有没有办法把它粘在桌子上?预先感谢您的帮助。

标签: rggplot2gridextra

解决方案


您应该使用下一个参数来找到最佳位置

  • 高度;
  • 宽度;
  • 文本格罗布。

例如,这个:

grid.arrange(table_scale, top = textGrob("Really looks \n better now?", x = 0, hjust = -1), left = "I'm near,\n my man", heights = c(2,1), widths = c(1,1.5))

给你看这个:

在此处输入图像描述


推荐阅读