Search code examples
rflextable

How to Specify Width and Height of a Flextable


I have a flextable that I would like to modify the length and width of to create a 3.5in x 3.5in table. I've tried looking around, but have so far found no easy way of manipulating table dimensions. Is anyone aware of a way to specify flextable length and height

Example code

library(flextable)

#read in data
data(mtcars)

#create flextable
ft<-flextable(mtcars[1:10,1:11])
ft

#save flextable
ft %>% save_as_image("../PATH/NAME.png")


Solution

  • To save your flextable as a plot, you should use package 'ragg' and command plot()(or gen_grob()).

    library(flextable)
    
    #read in data
    data(mtcars)
    
    #create flextable
    ft <- flextable(mtcars[1:10,1:11])
    ft
    
    #save flextable
    ragg::agg_png(filename = "test.png", width = 3.5, height = 3.5, units = "in", res = 200)
    plot(ft)
    dev.off()
    

    enter image description here