简体   繁体   English

在 R Markdown HTML 输出文件中嵌入可缩放图像

[英]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 .我目前正在尝试找到一种方法,以可扩展的方式将外部图像 (PNG) 嵌入到我的 R markdown HTML 输出文件中。

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.到目前为止我所尝试的只是将它们设置为等于 HTML 文件中可用空间的宽度(不知道有多少像素,可能在 800px 左右),即使原始图像大小为 ~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.我想要的是,当我增加 HTML 查看器的窗口大小时,图像也会增加,至少达到它们的原始分辨率。 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.您可能想要使用out.width而不是fig.widthfig.height ,以及百分比,这将是文本区域的百分比。 You can use it with include_graphics() .您可以将它与include_graphics() If you do not set out.height , the ratio will stay ok.如果您不设置out.height ,比例将保持out.height

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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