fakechek
fakechek

Reputation: 241

Embedding scalable images in R Markdown HTML output file

I'm currently trying to find a way to embed external images (PNG) in my R markdown HTML output file in a scalable way.

What I have tried so far only sets them to a width equal to the space available in HTML file (don't know how much that is in pixels, maybe around 800px) even though the original image size is ~1500x700.

What I would like is that when I increase the window size of the HTML viewer that also the images increase, at least up to their original resolution. Down-scaling works without problems.

My attempts:

```{r fig.width=100, fig.height=55, echo=FALSE}
library(png)
library(grid)
img <- readPNG("images/image.png")
grid.raster(img)
```

and

<img src="images/image.png">

...without success.

Anybody got an idea how to do that? I would really appreciate your help :)

Upvotes: 1

Views: 327

Answers (1)

S&#233;bastien Rochette
S&#233;bastien Rochette

Reputation: 6671

You may want to use out.width instead of fig.width and fig.height, with percentage, which will be percentage of the text area. You can use it with include_graphics(). If you do not set out.height, the ratio will stay ok.

```{r, echo=FALSE, out.width='80%'}
knitr::include_graphics("images/image.png")
```

Upvotes: 1

Related Questions