问题描述
请耐心等待,因为我是在这里/R 上发帖的新手。
我希望在 R 中使用 Plotly 创建甘特图,但对于每个任务,我将有多个条目,例如一个任务在 10:00 - 11:00 开始,然后在 13:00 - 14:00 等停止并继续,所以每个“行”会有多行。
我可以在 ggplot 中轻松做到这一点,但它在 plotly 中看起来好多了 - 但是我并没有取得太大的成功!
我在 ggplot 中的代码是这样的:
library(chron)
library(ggplot2)
library(tidyverse)
gc1<-data.frame(item = c(1,2,3,4,5),project_element = c("Task 1","Task 1","Task 2","Task 3","Task 4"),activity = c("do this","do this","do that","and again","double time"),start_time = c(45.50,65.70,25.03,10.3,11.02),duration = c(10.0,34.8,10.1,78.9,5.0))
#make a column specifying start/end times and convert to time.
gc2<-gc1 %>%
mutate(end_time = start_time+duration) %>%
gather("state","time",6) %>%
mutate(time = chron(times=time),duration = chron(times=duration))
ggplot(gc2,aes(time,activity,color = project_element,group=item)) +
geom_line(size = 10) +
labs(x="seconds(k)",y=NULL,title="Project timeline")
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)