我在使用tableGrob()和注解_custom()来调整绘制在绘图上的表格中文本的大小时遇到一些问题。本质上,我希望表中的字体较小,以便整个表较小。我已经检查了tableGrob()文档,并已尽我所能地对其进行了跟踪,但是由于它引发错误,因此我必须做错了什么。
这是一个可重现的示例:
library(ggplot2)
library(grid)
library(gridExtra)
df <- data.frame(x=seq(1,10),y=seq(11,20))
table <- data.frame(x=seq(1,3),y=seq(4,6))
ggplot(df,aes(x=x,y=y)) + geom_point() +
annotation_custom(tableGrob(table,rows=NULL),xmin=0,xmax=3,ymin=15,ymax=20) # plot drawn successfully without text resizing
ggplot(df,aes(x=x,y=y)) + geom_point() +
annotation_custom(tableGrob(table,rows=NULL,gpar.coretext = gpar(col = "black", cex = 0.8)),xmin=0,xmax=3,ymin=15,ymax=20)
# error when attempting to resize text following tableGrob documentation
这是我运行第二个ggplot()命令时遇到的错误:
Error in gtable_table(d, name = "core", fg_fun = theme$core$fg_fun, bg_fun = theme$core$bg_fun, :
unused argument (gpar.coretext = list(col = "black", cex = 0.8))
任何帮助深表感谢!
如果你只是希望所有的文字在你的桌子小,使用base_size
在ttheme_default
:
library(ggplot2)
library(grid)
library(gridExtra)
df <- data.frame(x=seq(1,10),y=seq(11,20))
table <- data.frame(x=seq(1,3),y=seq(4,6))
ggplot(df,aes(x=x,y=y)) +
geom_point() +
annotation_custom(tableGrob(table,rows=NULL, theme = ttheme_default(base_size = 8)),
xmin=0,xmax=3,ymin=15,ymax=20)
由reprex软件包(v0.3.0)创建于2020-03-05
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句