Reputation: 69
I am currently trying to create a plot that has a barchart of coefficients in the top 7/8 of the plot, and a table with statistics in the bottom 1/8. After creating the plot, I save it to a pdf file, which I've been doing with ggsave() and would like to keep that functionality. The program was originally built for just the barcharts, and I am adding in the statistics table.
I am at a loss on how to make this happen, or if I'm even thinking of it the right way.
Initially, I attempted:
tablestats <- grid.table(stats, rows = NULL)
grid.arrange(plt, tablestats, nrow = 2)
But I can't have a non grob in the above function.
Then I tried:
layout(matrix(c(1, 1, 1, 1, 1, 1, 2, 2, 2), 3, 3, byrow = TRUE))
plt <- plt + tablestats
print(plt)
But this only plots the barchart.
I've also tried the par(mfrow()) method, but it seemingly ignores the table when plotting.
Does anyone have any advice on how to build something like this or similar?
Upvotes: 0
Views: 470
Reputation: 56
I think the problem here is that you have to use tableGrob()
to define tablestats and not grid.table()
.
As stated in R: gridExtra - How to plot a Summary as table? :
To combine different tables / plots using grid.arrange they need to be grobs (grid GRaphcal OBjects). So you cannot pass the results from grid.table to grid.arrange as it is not a grob (it actually plots the tableGrob directly). For this you need to pass the tableGrob.
After that you can use grid.arrange()
as you did.
Upvotes: 1