Skip to content

Instantly share code, notes, and snippets.

@adamribaudo
Last active June 17, 2022 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adamribaudo/20833bb6907570866d021c2818de750b to your computer and use it in GitHub Desktop.
Save adamribaudo/20833bb6907570866d021c2818de750b to your computer and use it in GitHub Desktop.
How to create high quality image output in R Notebooks?
---
title: "R Notebook"
output: html_notebook
---
The following image uses the default chunk settings and is generally low quality.
```{r}
library(tidyverse)
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(color = class)) +
geom_smooth(se = FALSE) +
labs(title = "Fuel efficiency generally decreases with engine size")
```
The following image uses chunk settings with specific figure width and height. The image is high quality, but the fonts do not scale with the figure.
```{r fig.width=12,fig.height=8}
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(color = class)) +
geom_smooth(se = FALSE) +
labs(title = "Fuel efficiency generally decreases with engine size")
```
The following image uses chunk settings with a DPI of 300. The image is the same quality as the first image (low quality).
```{r dpi=300}
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(color = class)) +
geom_smooth(se = FALSE) +
labs(title = "Fuel efficiency generally decreases with engine size")
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment