在这篇带有 R 的甘特图之后,我使用与链接相同的数据结构将数据存储在 data.frame 中。代码如下(注意前 4 行是由 powerBI 自动生成的,我无法修改它。
df <- data.frame(task = c("task1", "task2", "task3"),
status = c("done", "active", "crit"),
pos = c("first_1", "first_2", "first_3"),
start = c("2014-01-06", "2014-01-09", "after first_2"),
end = c("2014-01-08", "3d", "5d"))
#Create dataframe
dataset <- data.frame(end, start, status, task, pos)
#Remove duplicated rows
# dataset <-unique(dataset)
df <- dataset
library(tidyr)
library(DiagrammeR)
library(dplyr)
mermaid(
paste0(
# mermaid "header", each component separated with "\n" (line break)
"gantt", "\n",
"dateFormat YYYY-MM-DD", "\n",
"title A Very Nice Gantt Diagram", "\n",
# unite the first two columns (task & status) and separate them with ":"
# then, unite the other columns and separate them with ","
# this will create the required mermaid "body"
paste(df %>%
unite(i, task, status, sep = ":") %>%
unite(j, i, pos, start, end, sep = ",") %>%
.$j,
collapse = "\n"
), "\n"
)
)
运行 R 脚本时,我收到以下错误消息。
没有创建图像。R 代码没有产生任何视觉效果。确保您的 R 脚本生成到 R 默认设备的绘图。
请指教为什么会这样?谢谢佩迪