如何在R的ggplot2图的右上角添加自定义表?

时间:2014-04-02 18:22:52

标签: r ggplot2

我想在下图的右上角添加一个自定义表格(或文本):

Without a table

所以它看起来像这样:

With a table

我尝试过使用

annotation_custom(tableGrob(mynames), xmin=-1, xmax=7, ymin=0, ymax=-1)

但它将表格添加到绘图区域的顶部,我无法将其移动到右上角(上方"图例")。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

感谢@infominer我找到了解决方案。这就是诀窍:

ggpl <- ggplot(...)
tableNames <- tableGrob(printNodes)
grid.arrange(ggpl, tableNames, ncol=2, main="Monthly Data")

我们的想法是,不要使用annotation_custom()向Grid图形框架中的图形设备添加文本。