Search code examples
rdataframeggplot2kableextra

How to save a table as an image or PDF


I've made a table for my data, and it turned out to be very long, I need to scroll down (in the plot window) to see all of it, so I cant crop it and its not working to save it as a picture using ggsave. I need the font to be big so I can't make it smaller.

This is the code:

phto = kable(features_table) %>% kable_styling(latex_options = "striped", font_size = 25)

phto 

It turned out to be something like this:

enter image description here

How can I save the whole table in a pdf or an image to see it all without scrolling?


Solution

  • It is a kableExtra object, not a ggplot object, use save_kable:

    library(kableExtra)
    
    kk <- kable(mtcars) %>%
      kable_styling(latex_options = "striped", font_size = 25)
    
    #We might need to install PhantomJS:
    #webshot::install_phantomjs()
    
    save_kable(kk, "x.pdf")