使用 R 的甘特图 - 无法使用 DiagrammeR 和 R Studio 输出

Gantt Chart with R - Can't Output utilizing DiagrammeR and R Studio

OS: Windows 7, R版本:3.4.3, R 工作室:1.1.383

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

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

我的临时解决方案是使用 Window 的截图工具来截取我自己的 'Zoom' 屏幕截图,但这并不可取。 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
")

您可以先将 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
    ")