2

操作系统:Windows 7,R 版本:3.4.3,R Studio:1.1.383

下面的代码使用 R 的 DiagrammeR 包生成了一个漂亮的甘特图。我在导出这个包的输出时遇到问题。在 R Studio 中,我可以单击Zoom并显示我的甘特图的漂亮全屏图像。然后我继续Export > Copy to Clipboard,当我粘贴时,我将这个奇怪的裁剪版本的图像粘贴到我的目的地。

裁剪的奇怪之处在于它截取了实际图像的部分屏幕截图以及我的 R Studio 会话的一部分并将两者相加。好像坐标没了 我也试过Export > Save as Image了,同样的问题发生了。漏洞??我以相同的方式从 ggplot2 输出了许多图形,但这永远不会发生。

我的临时解决方案是使用 Window 的截图工具来拍摄我自己的“缩放”截图,但这并不可取。DiagrammeR 使用美人鱼降价,无论这意味着什么,它的价值。

library(DiagrammeR)
mermaid("
gantt
dateFormat  YYYY-MM-DD
title A Very Nice Gantt Diagram

section Basic Tasks
This is completed             :done,          first_1,    2014-01-06, 2014-01-08
This is active                :active,        first_2,    2014-01-09, 3d
Do this later                 :               first_3,    after first_2, 5d
Do this after that            :               first_4,    after first_3, 5d

section Important Things
Completed, critical task      :crit, done,    import_1,   2014-01-06,24h
Also done, also critical      :crit, done,    import_2,   after import_1, 2d
Doing this important task now :crit, active,  import_3,   after import_2, 3d
Next critical task            :crit,          import_4,   after import_3, 5d

section The Extras
First extras                  :active,        extras_1,   after import_4,  3d
Second helping                :               extras_2,   after extras_1, 20h
More of the extras            :               extras_3,   after extras_1, 48h
")
4

1 回答 1

2

您可以先将 html 小部件保存为 html 文件,然后使用webshot将其保存为 png 文件。

htmlwidgets::saveWidget(m, file="m.html")
webshot::webshot("m.html", "m.png")

数据:

library(DiagrammeR)
m <- mermaid("
    gantt
    dateFormat  YYYY-MM-DD
    title A Very Nice Gantt Diagram

    section Basic Tasks
    This is completed             :done,          first_1,    2014-01-06, 2014-01-08
    This is active                :active,        first_2,    2014-01-09, 3d
    Do this later                 :               first_3,    after first_2, 5d
    Do this after that            :               first_4,    after first_3, 5d

    section Important Things
    Completed, critical task      :crit, done,    import_1,   2014-01-06,24h
    Also done, also critical      :crit, done,    import_2,   after import_1, 2d
    Doing this important task now :crit, active,  import_3,   after import_2, 3d
    Next critical task            :crit,          import_4,   after import_3, 5d

    section The Extras
    First extras                  :active,        extras_1,   after import_4,  3d
    Second helping                :               extras_2,   after extras_1, 20h
    More of the extras            :               extras_3,   after extras_1, 48h
    ")
于 2018-01-26T01:36:28.607 回答