1

A follow-up question to this: R save table as image

Is there any way to add Custom Titles and Headings to images generated by the following code?

library(ggplot2)
library(gridExtra)
df <- data.table(a=1:10, b=11:20,c=21:30, d=31:40)
png("test.png")
p<-tableGrob(df)
grid.arrange(p)
dev.off()

The above code gives me the following output:

![enter image description here

I want to add titles to the image and save them as files on my disk, so that I can use them in other documents and presentations.

Expecting something like this:

enter image description here

Or if there's a smarter way to do it in R, it would be very helpful. Again, all I am trying to do is create tables and export them to individual image files (that have appropriate titles in the images).

1 Answers1

1

You can use grid.arrange.

library(ggplot2)
library(gridExtra)
library(data.table)

df <- data.table(a=1:10, b=11:20,c=21:30, d=31:40)
png("test.png")
p <- tableGrob(df)
grid.arrange(top = "Title", p)
dev.off()
Laura Siepman
  • 76
  • 1
  • 4