Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase plot resolution in Quarto book using ggplot2

Tags:

r

ggplot2

quarto

When rendering a book in R, Quarto saves the plot images generated in each chapter within the ./chapter_name/figure-html directories. By default, images are saved with a resolution that is good enough for online book websites, but not good enough for printing.

Is there a way to, at least temporarily, generate all ggplots in higher resolution so we can send them to production to print the book ?

ps. The Quarto documentation is great, but they don't mention any info om plot resolutions on their page.

like image 396
rafa.pereira Avatar asked Oct 23 '25 09:10

rafa.pereira


1 Answers

As @tarleb mentioned, setting fig-dpi in the YAML format options is one solution. However, the ggsave() default is already 300, so for printing, 600 might be preferred.

Nonetheless, even better would be using lossless vector graphics. The Quarto PDF Format uses .pdf for figures by default. But that usually doesn't work well with HTML. However, you could set fig-format to svg.

format:
  html: 
    fig-format: svg

https://quarto.org/docs/reference/formats/html#figures

like image 131
Lennart Avatar answered Oct 25 '25 23:10

Lennart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!