Last active
June 17, 2022 10:12
-
-
Save adamribaudo/20833bb6907570866d021c2818de750b to your computer and use it in GitHub Desktop.
How to create high quality image output in R Notebooks?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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