当使用RMarkdown + Knitr制作我的代码/绘图的HTML输出时,绘图图像总是在RStudio中按预期显示,并且在块选项中指定了正确的宽度/高度尺寸,但是如果我然后使用Knitr放置所有内容在HTML文档中,这些图都被调整为较小的默认值。
在新标签中分别查看每个图表会根据需要显示它们的大尺寸,但为什么它们不能在HTML中显示。我可以为此更改任何设置吗?
答案 0 :(得分:1)
fig.width
和out.width
之间存在差异,fig.height
和out.height
之间也存在差异。 fig.*
控制保存的图形大小,out.*
控制图像在输出中的缩放方式。
例如,以下.Rmd文件将生成相同的图形两次,但显示的宽度和高度不同。
---
title: "Example graphic"
---
```{r echo = FALSE, fig.width = 14, fig.height = 9, out.width = "588", out.height = "378"}
library(ggplot2)
ggplot(mpg, aes(x = year, y = cyl)) + geom_point()
```
```{r echo = FALSE, fig.width = 14, fig.height = 9, out.width = "1026", out.height = "528"}
library(ggplot2)
ggplot(mpg, aes(x = year, y = cyl)) + geom_point()
```