7

When using JupyterLab, there is a command %config InlineBackend.figure_format = 'svg' that displays plots as svg. The quality is awesome. I would like to ask if there is a similar command for Rnotebook, i.e.

  • Display plots inside Rnotebook as svg.

  • Display plots in the output html as svg.

1 Answer 1

6

For every code chunk that you want to produce svg output, you simply set the dev = 'svg' chunk option. Or you can set this option globally with knitr::opts_chunk$set(dev = 'svg') at the beginning of your markdown document.

Save the following as a .Rmd file, knit, and see what you get.

---
title: "Untitled"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(dev = 'svg') # set output device to svg
```

A simple plot, as svg file:

```{r}
library(ggplot2)

ggplot(mtcars, aes(mpg, disp, color = hp)) +
  geom_point() +
  scale_color_viridis_c()
```
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.