1

I'm having an issue with the low-quality graph output when saving html_notebook in R markdown.

I tried changing the dpi and fig.retina settings of the chunks but didn't see an impact. This only happens when rendering .nb.html preview file. When I knit the document as an html file, I have a lot better quality. I'm attaching a comparison below:

image comparison

I'm using html_notebook markdown for interact with the code, and would like to have the ability to save at the maximum quality to be able to generate reports quickly (rather than knitting everything from scratch).

This is a reproducible example to be executed as an .rmd file. Execute the code and save the .rmd file to create .nb.html. And then, knit to html to get the higher quality .html file.

---
title: "Test"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
  html_document:
    df_print: paged
    toc: yes
    toc_depth: '3'
    toc_float: yes
  html_notebook:
    toc: yes
    toc_depth: "3"
    toc_float: yes
---

# Plot

```{r, fig.width=4, fig.height=3}

suppressPackageStartupMessages(library(ggplot2))

ggplot(iris)+
  geom_point(aes(x=Sepal.Width, y= Sepal.Length, color=Petal.Width))+
  theme_minimal()

```

Any ideas on how to change this behavior?

Thanks so much!

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
Atakan
  • 416
  • 3
  • 14
  • 1
    [Reproducible Example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) please. – M-- Jun 15 '19 at 08:00
  • When I ran your example the first time, I got no plot at all. Then I ran the chunk in RStudio, and previewing the notebook showed the figure. So my guess is that it is just copying the preview from RStudio to the web page: if they differ in size by a lot, you'd see the fuzzy text. – user2554330 Jun 15 '19 at 13:02
  • Yeah, I think that is the issue. When the notebook html is being saved, it saves the figure the way it is visualized (adaptively) in the RStudio session. I'd like the images to be saved at the publication quality when html notebook is saved. Is this not possible? – Atakan Jun 16 '19 at 20:03
  • Anybody out there to chime in? – Atakan Aug 01 '19 at 18:06

1 Answers1

0

I believe you have to knit the notebook to html_document for the image quality settings to work. A chunk with these settings works for me with html_document to produce high quality images. I don't know how to produce higher quality images with html_notebook; perhaps it's impossible.

knitr::opts_chunk$set(dpi = 300, dev = "svg")

Arthur
  • 1,248
  • 8
  • 14