【问题标题】:RNotebook not picking up default figure sizesRNotebook 没有选择默认的图形大小
【发布时间】:2018-01-03 08:00:27
【问题描述】:

比方说,我有以下 RNotebook 块来绘制图形:

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

现在,我想将其绘制为 10x10 的图形。我可以用这个:

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

而且效果很好。但是说我想重新定义全局图形大小并默认为那些。我试过用这个:

```{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
```

但这并没有正确调整图形大小,但是当我检查它们时,默认图形大小已更改。有人可以解释我要去哪里错了吗?

【问题讨论】:

  • 您是否尝试将knitr::opts_chunk$set(fig.height = 10, fig.width = 10) 放入您的设置块中?
  • 如果我不想在笔记本中更改这些参数,我认为这很好,这就是我想要做的。看起来这是 RNotebook 目前无法真正处理的事情。
  • 将选项“fig.width=10, fig.height=10”放在块头中怎么样?

标签: r knitr r-markdown rnotebook


【解决方案1】:

稍微玩一下,使用 html_document 输出类型,如果您将 opts_chunk 调用放在您希望使用它的块之前的块中,它就可以工作。

---
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)
```

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    • 2020-12-30
    • 2013-10-10
    • 1970-01-01
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多