I would like to export a data frame as a (png) image. I've tried with this code, but the table get clipped vertically.
library(ggplot2) library(gridExtra) df <- data.frame(a=1:30, b=1:30) png("test.png") p<-tableGrob(df) grid.arrange(p) dev.off()
Is there a way to avoid this behaviour without having to set manually the size of the image?
If you're running R through Rstudio, then the easiest way to save your image is to click on the “Export” button in the Plot panel (i.e., the area in Rstudio where all the plots have been appearing). When you do that you'll see a menu that contains the options “Save Plot as PDF” and “Save Plot as Image”.
We can create a table by using as. table() function, first we create a table using matrix and then assign it to this method to get the table format. Example: In this example, we will create a matrix and assign it to a table in the R language.
You can change this behavior by specifying a height and width.
png("test.png", height=1000, width=200) p<-tableGrob(df) grid.arrange(p) dev.off()
Anyway, it is usually not very helpful to save tables as pictures.
You can do like this:
library(gridExtra) png("test.png", height = 50*nrow(df), width = 200*ncol(df)) grid.table(df) dev.off()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With