【问题标题】:Gantt Chart with R - Can't Output utilizing DiagrammeR and R Studio带有 R 的甘特图 - 无法使用 DiagrammeR 和 R Studio 输出
【发布时间】:2018-07-04 23:13:30
【问题描述】:

操作系统: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 的截图工具来拍摄我自己的“缩放”截图,但这并不可取。 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的结果。如果您在 RStudio 查看器窗口中单击“导出”选项,您可以选择“另存为网页”并将输出保存到 html 文件中,然后您可以在浏览器中打开该文件。 (希望有人会提出一种程序化和可重现的方式来保存输出。)
  • 希望您能在这里得到更好的答案,但您也可以特别咨询documentation for `DiagrammeRmermaid section 以获取更多信息。

标签: r rstudio markdown diagrammer


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-13
    • 1970-01-01
    • 1970-01-01
    • 2019-06-04
    • 2020-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多