Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove borders around ggplot2 in quarto revealjs presentation

I am trying to make a quarto presentation using revealjs. When the ggplot renders (page 2; see below for a reproducible example) there is a black border around the rendered plot. How can one remove this border?

Quarto revealjs presentation code:

---
title: "Test Presentation"
format: 
  revealjs:
    theme: [default, custom.scss]
---

## Some plot

```{r}
library(ggplot2)

ggplot(mtcars) +
  geom_boxplot(aes(as.factor(cyl), disp, fill = cyl)) +
  theme_minimal() +
  theme(
      legend.position = "none",
      panel.grid = element_blank(),
      axis.title = element_text(size = 20, color = "#fefefe"),
      axis.text = element_text(size = 15, color = "#fefefe"),
      plot.title = element_text(size = 20, color = "#fefefe"),
      plot.background = element_rect(fill = "#505050"),
      panel.background = element_rect(fill = "#505050"),
      axis.line.x.top = element_line(color = "#fefefe"),
      axis.line.x.bottom = element_line(color = "#fefefe"),
      axis.line.y.left = element_line(color = "#fefefe"),
      axis.line.y.right = element_line(color = "#fefefe")
    ) +
    guides(x.sec = "axis", y.sec = "axis")
```

custom.scss code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

/*-- scss:defaults --*/

// fonts
$font-family-sans-serif: "Palatino Linotype", "Book Antiqua", Palatino,
  FreeSerif, serif !default;

// colors
$body-bg: #505050;
$body-color: #ffffff;
$link-color: #51483d !default;
$selection-bg: #26351c !default;

// headings
$presentation-heading-font: "Palatino Linotype", "Book Antiqua", Palatino,
  FreeSerif, serif !default;
$presentation-heading-color: #ffffff !default;

/*-- scss:rules --*/

.reveal a {
  line-height: 1.3em;
}

>Solution :

To remove the border around your plot set e.g. color = NA or size=NA in theme option plot.background:

---
title: "Test Presentation"
format: 
  revealjs:
    theme: [default, custom.scss]
---

## Some plot

```{r}
library(ggplot2)

ggplot(mtcars) +
  geom_boxplot(aes(as.factor(cyl), disp, fill = cyl)) +
  theme_minimal() +
  theme(
      legend.position = "none",
      panel.grid = element_blank(),
      axis.title = element_text(size = 20, color = "#fefefe"),
      axis.text = element_text(size = 15, color = "#fefefe"),
      plot.title = element_text(size = 20, color = "#fefefe"),
      plot.background = element_rect(fill = "#505050", color = NA),
      panel.background = element_rect(fill = "#505050"),
      axis.line.x.top = element_line(color = "#fefefe"),
      axis.line.x.bottom = element_line(color = "#fefefe"),
      axis.line.y.left = element_line(color = "#fefefe"),
      axis.line.y.right = element_line(color = "#fefefe")
    ) +
    guides(x.sec = "axis", y.sec = "axis")
```

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading