简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM