Reputation: 1120
I want to set a global color scheme in Rmarkdown, I read that this is possible with options
but I tried this without success:
---
title: "Iris"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
options(ggplot2.continuous.color = "viridis")
options(ggplot2.continuous.fill = "viridis")
options(ggplot2.discrete.fill = "viridis")
```
```{r}
library(tidyverse)
iris %>% ggplot(aes(Sepal.Length, Sepal.Width, color = Species)) +
geom_point()
```
The plot I get uses the default color scheme, and I want the viridis scheme. Any help will be greatly appreciated.
Upvotes: 1
Views: 1497
Reputation: 16940
Following this excellent blog post by Jim Hester, you can reassign to the default scale_colour_*()
functions the scales you want:
---
title: "Iris"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
scale_colour_continuous <- scale_colour_viridis_c
scale_colour_discrete <- scale_colour_viridis_d
scale_colour_binned <- scale_colour_viridis_b
```
```{r}
iris %>% ggplot(aes(Sepal.Length, Sepal.Width, color = Species)) +
geom_point()
```
Upvotes: 4