我遇到了一些问题,想要调整使用tableGrob()和annotation_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))
任何帮助都非常感激!
0.9.1
的包的文档,而当前版本是2.3.0
,帮助页面在这里:https://www.rdocumentation.org/packages/gridExtra/versions/2.3/topics/tableGrob。新版本更倾向于使用主题。 - MrFlick