R save table as image

后端 未结 3 1294
时光取名叫无心
时光取名叫无心 2020-12-10 01:36

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)

         


        
相关标签:
3条回答
  • 2020-12-10 02:12

    You can do like this:

    library(gridExtra)
    png("test.png", height = 50*nrow(df), width = 200*ncol(df))
    grid.table(df)
    dev.off()
    
    0 讨论(0)
  • 2020-12-10 02:17

    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.

    0 讨论(0)
  • 2020-12-10 02:18

    This works just fine:

    library(gridExtra)
    
    df = data.frame("variables" = c("d_agr","d_def","d_frig","d_hidro","d_roads","d_silos"),
    "coeficient" = c(0.18,0.19,-0.01,-0.25,-0.17,0.09))
    
    png("output.png", width=480,height=480,bg = "white")
    grid.table(df)
    dev.off()
    
    0 讨论(0)
提交回复
热议问题