Rlearner
Rlearner

Reputation: 351

How to add a custom table to the top-right corner of a ggplot2 plot in R?

I would like to add a custom table (or text) to the top-right corner of the following plot:

Without a table

so it looks like this:

With a table

I have tried to use

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

but it adds the table on top of the plot area and I cannot move it to the top-right corner (above "Legend").

Any suggestions?

Upvotes: 1

Views: 1461

Answers (1)

Rlearner
Rlearner

Reputation: 351

Thanks to @infominer I found the solution. This did the trick:

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

The idea is that instead of using annotation_custom() add text to a graphic device in the Grid graphics framework.

Upvotes: 1

Related Questions