代码之家  ›  专栏  ›  技术社区  ›  user1420372

rmarkdown/knitr,匹配物理图形大小和显示的HTML大小

  •  0
  • user1420372  · 技术社区  · 8 年前

    我正在使用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)
    ```
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   user2554330    8 年前

    out.height="5.29in", out.width="5.89in" height width img