1

Say, I have the following RNotebook chunk that plots a figure:

```{r}
plot(cars)
```

Now, I want to plot it as a 10x10 figure. I could use this:

```{r fig.height = 10, fig.width = 10}
plot(cars)
```

and that works fine. But say I want to redefine global figure sizes and default to those. I tried using this:

```{r}
knitr::opts_chunk$set(fig.height = 10, fig.width = 10)
plot(cars)
knitr::opts_chunk$get()$fig.width
knitr::opts_chunk$get()$fig.height
```

but this doesn't resize the figure correctly and yet the default figure sizes have been changed when I check them. Can someone explain where I'm going wrong?

Dan
  • 11,370
  • 4
  • 43
  • 68
  • Have you tried putting `knitr::opts_chunk$set(fig.height = 10, fig.width = 10)` in your setup chunk? – aosmith Jul 28 '17 at 17:05
  • I think that's fine if I don't want to change those parameters part way through my notebook, which is what I'm trying to do. It looks like this is something that RNotebook can't really handle at present. – Dan Jul 28 '17 at 17:33
  • What about putting the options "fig.width=10, fig.height=10" in the chunk header? – buggaby Sep 25 '20 at 18:01

1 Answers1

0

A little playing around and, with an html_document output type, it works if you put the opts_chunk call in the chunk ahead of where you want it to be used.

---
title: "R Notebook"
output:
  html_document
---

```{r, setup}
knitr::opts_chunk$set(fig.width = 5)
```

```{r}
knitr::opts_chunk$set(fig.width = 8)
```

```{r}
plot(cars)
```

```{r}
knitr::opts_chunk$set(fig.width = 12)
```

```{r}
plot(cars)
```
buggaby
  • 359
  • 2
  • 13