knitr 中非常宽的图形 HTML
Very wide graphics in knitr HTML
我正在使用 r markdown 和 Rstudio 创建一个 html 报告。我有一些我想要非常宽的图形,但是,即使在块选项中使用 fig.width
和 out.width
时,输出中的宽度似乎也有限制。例如,以下三个代码块生成的图形在最终输出中具有相同的宽度:
```{r,fig.height=7,fig.width=12,echo=FALSE}
plot(rnorm(1000),type="l")
```
```{r,fig.height=7,fig.width=40,echo=FALSE}
plot(rnorm(1000),type="l")
```
```{r,fig.height=7,fig.width=40,echo=FALSE,out.width=20000}
plot(rnorm(1000),type="l")
```
我已经使用 options(width=LARGENUMBER)
进行输出(例如 print
等),这似乎很适合打印表格,但我还没有找到一种方法来制作这些图表更宽。
有什么建议吗?
您可以添加类似这样的内容
---
output: html_document
---
<style>
img {
max-width: none;
/* other options:
max-width: 200%;
max-width: 700px;
max-width: 9in;
max-width: 25cm;
etc
*/
}
</style>
```{r,fig.height=7,fig.width=12,echo=FALSE}
plot(rnorm(1000),type="l")
```
```{r,fig.height=7,fig.width=40,echo=FALSE}
plot(rnorm(1000),type="l")
```
```{r,fig.height=7,fig.width=40,echo=FALSE}
plot(rnorm(1000),type="l")
```
或者更好的是用
设置你的knitr.css文件
img {
max-width: 200%;
}
或任何你喜欢的,然后使用
---
output:
html_document:
css: ~/knitr.css
---
我正在使用 r markdown 和 Rstudio 创建一个 html 报告。我有一些我想要非常宽的图形,但是,即使在块选项中使用 fig.width
和 out.width
时,输出中的宽度似乎也有限制。例如,以下三个代码块生成的图形在最终输出中具有相同的宽度:
```{r,fig.height=7,fig.width=12,echo=FALSE}
plot(rnorm(1000),type="l")
```
```{r,fig.height=7,fig.width=40,echo=FALSE}
plot(rnorm(1000),type="l")
```
```{r,fig.height=7,fig.width=40,echo=FALSE,out.width=20000}
plot(rnorm(1000),type="l")
```
我已经使用 options(width=LARGENUMBER)
进行输出(例如 print
等),这似乎很适合打印表格,但我还没有找到一种方法来制作这些图表更宽。
有什么建议吗?
您可以添加类似这样的内容
---
output: html_document
---
<style>
img {
max-width: none;
/* other options:
max-width: 200%;
max-width: 700px;
max-width: 9in;
max-width: 25cm;
etc
*/
}
</style>
```{r,fig.height=7,fig.width=12,echo=FALSE}
plot(rnorm(1000),type="l")
```
```{r,fig.height=7,fig.width=40,echo=FALSE}
plot(rnorm(1000),type="l")
```
```{r,fig.height=7,fig.width=40,echo=FALSE}
plot(rnorm(1000),type="l")
```
或者更好的是用
设置你的knitr.css文件img {
max-width: 200%;
}
或任何你喜欢的,然后使用
---
output:
html_document:
css: ~/knitr.css
---