RMarkdown/Knitr,匹配实物尺寸和显示尺寸 HTML
RMarkdown/Knitr, matching physical figure size and displayed HTML size
我正在使用 RMarkdown 创建一个 html 文件(我的首选格式)。然后,我使用 officer 包创建一个 powerpoint (PPT)(其他人的首选格式),读取 .png 图像,这些图像在我编织文档时自动创建和保存(我相信这是 fig.path 时的默认设置指定)。
为了在整个 PPT 图形中获得一致的字体大小,我在每个 knitr 块 fig.width, out.width
等中指定等于相关 PPT 占位符尺寸。例如,如果 PPT 占位符为 5.29 英寸高 x 5.89 英寸宽,则在 knitr 块中我指定 out.height="5.29in", out.width="5.89in", fig.height=5.29, fig.width=5.89
)。这似乎在 PPT 文件方面有效,但它会导致 HTML 文件的数字非常小。有没有办法让 knitr 代码同时适用于 html 和 PPT,而不需要专门保存图像,例如使用 ggsave()?
以下是一些自动生成的测试代码:
---
title: "Test_Figure_Size"
output:
html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(fig.path = "Delete_Me/", echo=FALSE)
```
When you include out.height, out.width the figure is extremely small in the knitted html document, but perfectly sized as a .png file.
```{r pressure, echo=FALSE, out.height="5.29in", out.width="5.89in", fig.height=5.29, fig.width=5.89}
plot(pressure)
```
当您说 out.height="5.29in", out.width="5.89in"
时,这些值将作为 img
的 height
和 width
属性写入 HTML 输出。但是 height
和 width
是以像素表示的,所以你最终会得到一个大约 5 像素见方的数字。
我不使用 Powerpoint,但有没有办法以像素为单位指定图像大小,例如“589px”或类似的东西?然后它会使用与浏览器相同的比例尺,东西应该是一致的。
我正在使用 RMarkdown 创建一个 html 文件(我的首选格式)。然后,我使用 officer 包创建一个 powerpoint (PPT)(其他人的首选格式),读取 .png 图像,这些图像在我编织文档时自动创建和保存(我相信这是 fig.path 时的默认设置指定)。
为了在整个 PPT 图形中获得一致的字体大小,我在每个 knitr 块 fig.width, out.width
等中指定等于相关 PPT 占位符尺寸。例如,如果 PPT 占位符为 5.29 英寸高 x 5.89 英寸宽,则在 knitr 块中我指定 out.height="5.29in", out.width="5.89in", fig.height=5.29, fig.width=5.89
)。这似乎在 PPT 文件方面有效,但它会导致 HTML 文件的数字非常小。有没有办法让 knitr 代码同时适用于 html 和 PPT,而不需要专门保存图像,例如使用 ggsave()?
以下是一些自动生成的测试代码:
---
title: "Test_Figure_Size"
output:
html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(fig.path = "Delete_Me/", echo=FALSE)
```
When you include out.height, out.width the figure is extremely small in the knitted html document, but perfectly sized as a .png file.
```{r pressure, echo=FALSE, out.height="5.29in", out.width="5.89in", fig.height=5.29, fig.width=5.89}
plot(pressure)
```
当您说 out.height="5.29in", out.width="5.89in"
时,这些值将作为 img
的 height
和 width
属性写入 HTML 输出。但是 height
和 width
是以像素表示的,所以你最终会得到一个大约 5 像素见方的数字。
我不使用 Powerpoint,但有没有办法以像素为单位指定图像大小,例如“589px”或类似的东西?然后它会使用与浏览器相同的比例尺,东西应该是一致的。