Rich Rich - 3 years ago 163
CSS Question

Very wide graphics in knitr HTML

I am using r markdown and Rstudio to create an html report. I have some graphics that I would like to be extremely wide, however, there seems to be a limit to the width in the output even when using

fig.width
and
out.width
in the chunk options. For instance the following three code chunks produce figures which are the same width in the final output:

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


I have used
options(width=LARGENUMBER)
for output (e.g. such as
print
, etc.) which seems to work well for printing tables, but I have yet to find a a way to make these graphs any wider.

Any suggestions?

Answer Source

You could add something like this

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

or better yet set up your knitr.css file with

img {
    max-width: 200%;
}

or whatever you like, and use

---
output: 
  html_document:
    css: ~/knitr.css
---
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download