Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save a table as an image but also preserve its quality? R

Tags:

r

Looking for tips to save a table as an image with the quality seen in the RStudio Viewer. I've tried save_kable and as_image but both resulted in serious drops in quality.

Any other recommendations?

Code for reference:

library(htmlTable)
library(xtable)
library(kableExtra)
data(tli)
htmlTable(xtable(tli[1:10,),rnames=FALSE)%>%save_kable('table.png')`
like image 214
EconMatt Avatar asked Feb 25 '20 14:02

EconMatt


People also ask

How do I save a high quality image in R?

You can also specify the width and the height in pixels. In R GUI you will need to go to File → Save as and select the type of file you prefer. If you select Jpeg , you can also specify the quality of the resulting image. The last option is copying the image to the Clipboard.

How do you save a table as a picture?

The best way to convert table to image in Word is by saving it as a Picture. First, select the table and right-click on the table. Copy and paste it into a new document by using the Paste Special: Picture option. Finally, right-click on the pasted image and click on Save As Picture.

How do you save an image in R studio?

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”.

How do you save a chart as a picture in Word?

Click the chart that you want to save as a picture. Choose Copy from the ribbon, or press CTRL+C on your keyboard . Switch to the application you want to copy the chart to. If you're saving as a separate image file open your favorite graphics editor, such as Microsoft Paint.


Video Answer


1 Answers

The save_kable function has a ... argument which passes variables to webshot::webshot.

From the webshot README, you can generate higher quality screenshots with the zoom option, e.g.,

library(knitr)
library(kableExtra)
library(magrittr)

kable(iris[1:10,]) %>%
  kable_styling() %>%
  save_kable(file = "table_1.png")

kable(iris[1:10,]) %>%
  kable_styling() %>%
  save_kable(file = "table_2.png",
             zoom = 1.5)
like image 127
David Diaz Avatar answered Oct 03 '22 07:10

David Diaz