Remove background of plots
If you are using a non-white background color for your slides it can be bothersome to match the background of your plots. Setting dev.args = list(bg = 'transparent')
in your chunk option removes the background of your chart and it will show the background color of the slide instead.
Note, you most likely have to change the text colors of your chart to be move visible under the new background.
---
output:
xaringan::moon_reader:
css: ["default"]
lib_dir: libs
seal: FALSE
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
class: inverse
# Transperent Background
```{r, dev.args = list(bg = 'transparent'), fig.asp = 3/4, fig.align = 'center', echo = FALSE, out.width = "80%", dpi= 300, warning = FALSE}
library(ggplot2)
library(palmerpenguins)
ggplot(penguins) +
aes(bill_length_mm, bill_depth_mm,
color = species) +
geom_point() +
theme_minimal() +
theme(
text = element_text(colour = "grey90"),
axis.text = element_text(colour = "grey90"),
panel.grid = element_line(colour = "grey70")
) +
scale_color_manual(values = c("darkorange","purple","cyan4")) +
labs(title = "Bill depth and length")
```
Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".
For attribution, please cite this work as
Hvitfeldt (2021, May 22). Xaringan Gallery: Transparent Backgrounds for Plot. Retrieved from https://xaringan.gallery/examples/transparent-plot/
BibTeX citation
@misc{hvitfeldt2021transparent, author = {Hvitfeldt, Emil}, title = {Xaringan Gallery: Transparent Backgrounds for Plot}, url = {https://xaringan.gallery/examples/transparent-plot/}, year = {2021} }