programing

R이 있는 Gantt 관리도

stoneblock 2023. 7. 3. 22:30

R이 있는 Gantt 관리도

R에서 갠트 차트를 만들려면 어떻게 해야 합니까?

저는 세련된 것을 찾고 있습니다(거의 이렇게 보입니다). this

추신: 의존성 화살표 없이도 살 수 있었습니다.

이제 R에서 갠트 차트를 생성하는 몇 가지 우아한 방법이 있습니다.

Candela 사용

library(candela)

data <- list(
    list(name='Do this', level=1, start=0, end=5),
    list(name='This part 1', level=2, start=0, end=3),
    list(name='This part 2', level=2, start=3, end=5),
    list(name='Then that', level=1, start=5, end=15),
    list(name='That part 1', level=2, start=5, end=10),
    list(name='That part 2', level=2, start=10, end=15))

candela('GanttChart',
    data=data, label='name',
    start='start', end='end', level='level',
    width=700, height=200)

enter image description here

다이어그램 사용r

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
")

enter image description here

이 예제 및 기타 정보 찾기DiagrammeR 깃헙


데이터가 저장된 경우data.frame전달할 문자열을 만들 수 있습니다.mermaid()적절한 형식으로 변환합니다.

다음 사항을 고려합니다.

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"))

#   task status     pos         start        end
#1 task1   done first_1    2014-01-06 2014-01-08
#2 task2 active first_2    2014-01-09         3d
#3 task3   crit first_3 after first_2         5d

사용.dplyr그리고.tidyr(또는 좋아하는 데이터 논쟁 리소스):

library(tidyr)
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"
  )
)

@George Dontas가 댓글에 언급한 바와 같이, x축의 레이블을 'w.01, w.02'가 아닌 날짜로 변경할 수 있는 약간의 해킹이 있습니다.

위의 인어 그래프를 저장했다고 가정합니다.m수행:

m$x$config = list(ganttConfig = list(
  axisFormatter = list(list(
    "%b %d, %Y" 
    ,htmlwidgets::JS(
      'function(d){ return d.getDay() == 1 }' 
    )
  ))
))

이는 다음을 제공합니다.

enter image description here


타임비즈 사용

에서timevis GitHub:

timevisR에서 풍부하고 완전한 대화형 타임라인 시각화를 생성할 수 있습니다.타임라인은 Shiny 앱 및 R 마크다운 문서에 포함되거나 R 콘솔 및 R Studio Viewer에서 볼 수 있습니다.

library(timevis)

data <- data.frame(
  id      = 1:4,
  content = c("Item one"  , "Item two"  ,"Ranged item", "Item four"),
  start   = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14 15:00:00"),
  end     = c(NA          ,           NA, "2016-02-04", NA)
)

timevis(data)

이는 다음을 제공합니다.

enter image description here


플롯 사용

다음을 사용하는 다른 방법을 제공하는 이 게시물을 우연히 발견했습니다.plotly다음은 예입니다.

library(plotly)

df <- read.csv("https://cdn.rawgit.com/plotly/datasets/master/GanttChart-updated.csv", 
               stringsAsFactors = F)

df$Start  <- as.Date(df$Start, format = "%m/%d/%Y")
client    <- "Sample Client"
cols      <- RColorBrewer::brewer.pal(length(unique(df$Resource)), name = "Set3")
df$color  <- factor(df$Resource, labels = cols)

p <- plot_ly()
for(i in 1:(nrow(df) - 1)){
  p <- add_trace(p,
                 x = c(df$Start[i], df$Start[i] + df$Duration[i]), 
                 y = c(i, i), 
                 mode = "lines",
                 line = list(color = df$color[i], width = 20),
                 showlegend = F,
                 hoverinfo = "text",
                 text = paste("Task: ", df$Task[i], "<br>",
                              "Duration: ", df$Duration[i], "days<br>",
                              "Resource: ", df$Resource[i]),
                 evaluate = T
  )
}

p

이는 다음을 제공합니다.

enter image description here

그런 다음 추가 정보 및 주석을 추가하고 글꼴 및 색상을 사용자 지정할 수 있습니다(자세한 내용은 블로그 게시물 참조).

아주 오래된 질문입니다. 알고 있지만, 아마도 여기서 떠날 가치가 있을 것입니다. - 이 질문에 대한 대답에 만족하지 못합니다. - 저는 몇 달 전에 ggplot2 기반 갠트 차트를 만들기 위한 기본 패키지를 만들었습니다. : ganttrify(패키지의 자세한 내용은 패키지 읽기).

출력 예:

간단한ggplot2갠트 차트

먼저, 우리는 약간의 데이터를 만듭니다.

library(reshape2)
library(ggplot2)

tasks <- c("Review literature", "Mung data", "Stats analysis", "Write Report")
dfr <- data.frame(
  name        = factor(tasks, levels = tasks),
  start.date  = as.Date(c("2010-08-24", "2010-10-01", "2010-11-01", "2011-02-14")),
  end.date    = as.Date(c("2010-10-31", "2010-12-14", "2011-02-28", "2011-04-30")),
  is.critical = c(TRUE, FALSE, FALSE, TRUE)
)
mdfr <- melt(dfr, measure.vars = c("start.date", "end.date"))

이제 플롯을 그려보세요.

ggplot(mdfr, aes(value, name, colour = is.critical)) + 
  geom_line(size = 6) +
  xlab(NULL) + 
  ylab(NULL)

패키지 사용을 고려해 보십시오(버전 0.1.0은 2017년 8월 23일 CRAN에서 출시됨).

library(projmanr)

# Use raw example data
(data <- taskdata1)

taskdata1:

  id name duration pred
1  1   T1        3     
2  2   T2        4    1
3  3   T3        2    1
4  4   T4        5    2
5  5   T5        1    3
6  6   T6        2    3
7  7   T7        4 4,5 
8  8   T8        3  6,7

이제 Gantt를 준비하기 시작합니다.

# Create a gantt chart using the raw data
gantt(data)

enter image description here

# Create a second gantt chart using the processed data
res <- critical_path(data)
gantt(res)

enter image description here

# Use raw example data
data <- taskdata1
# Create a network diagram chart using the raw data
network_diagram(data)

enter image description here

# Create a second network diagram using the processed data
res <- critical_path(data)
network_diagram(res)

enter image description here

사용해 보십시오.

install.packages("plotrix")
library(plotrix)
?gantt.chart

패키지plan번다운 차트 및 갠트 다이어그램 생성을 지원하며 다음을 포함합니다.plot.gantt기능. R 그래픽 설명서 페이지를 참조하십시오.

Plotly의 R API Gantt 차트를 사용하여 R에서 PLOTLY를 사용하여 R을 만드는 방법도 참조하십시오.

GoogleVis 패키지를 사용하여 다음 작업을 수행할 수 있습니다.

datTL <- data.frame(Position=c(rep("President", 3), rep("Vice", 3)),
                    Name=c("Washington", "Adams", "Jefferson",
                           "Adams", "Jefferson", "Burr"),
                    start=as.Date(x=rep(c("1789-03-29", "1797-02-03", 
                                          "1801-02-03"),2)),
                    end=as.Date(x=rep(c("1797-02-03", "1801-02-03", 
                                        "1809-02-03"),2)))

Timeline <- gvisTimeline(data=datTL, 
                         rowlabel="Name",
                         barlabel="Position",
                         start="start", 
                         end="end",
                         options=list(timeline="{groupByRowLabel:false}",
                                      backgroundColor='#ffd', 
                                      height=350,
                                      colors="['#cbb69d', '#603913', '#c69c6e']"))
plot(Timeline)

enter image description here

출처: https://cran.r-project.org/web/packages/googleVis/vignettes/googleVis_examples.html

저에게 Gvistimeline은 이를 위한 최고의 도구였지만, 필요한 온라인 연결은 저에게 유용하지 않았습니다.그래서 저는 다음과 같은 패키지를 만들었습니다.vistime을사는하를 plotly(@Steven Beaupré의 답변과 유사), 확대 등을 할 수 있습니다.

https://github.com/shosaco/vistime

vistimeplotly.js.js를 사용하여 또는 .차트는 Shiny 앱에 포함되어 plotly_build()를 통해 조작할 수 있습니다.

install.packages("vistime")    
library("vistime")  

dat <- data.frame(Position=c(rep("President", 3), rep("Vice", 3)),
              Name = c("Washington", "Adams", "Jefferson", "Adams", "Jefferson", "Burr"),
              start = rep(c("1789-03-29", "1797-02-03", "1801-02-03"), 2),
              end = rep(c("1797-02-03", "1801-02-03", "1809-02-03"), 2),
              color = c('#cbb69d', '#603913', '#c69c6e'),
              fontcolor = rep("white", 3))

vistime(dat, events="Position", groups="Name", title="Presidents of the USA")

enter image description here

저는 위의 예제를 리치에서 사용하고 수정하여 매력적으로 작업했습니다.그의 모델이 수동으로 제공된 텍스트 항목이 아닌 CSV 데이터를 수집하는 방법을 보여주기 위해 수정된 버전입니다.

참고: Richie의 답변에 위/아래 코드가 작동하려면 2개의 패키지(모양 변경 및 ggplot2)가 필요하다는 표시가 누락되었습니다.

rawschedule <- read.csv("sample.csv", header = TRUE) #modify the "sample.csv" to be the name of your file target. - Make sure you have headers of: Task, Start, Finish, Critical OR modify the below to reflect column count.
tasks <- c(t(rawschedule["Task"]))
dfr <- data.frame(
name        = factor(tasks, levels = tasks),
start.date  = c(rawschedule["Start"]),
end.date    = c(rawschedule["Finish"]),
is.critical = c(rawschedule["Critical"]))
mdfr <- melt(dfr, measure.vars = c("Start", "Finish"))


#generates the plot
ggplot(mdfr, aes(as.Date(value, "%m/%d/%Y"), name, colour = Critical)) + 
geom_line(size = 6) +
xlab("Duration") + ylab("Tasks") +
theme_bw()

gem_segment in ggplot이 훌륭함을 발견했습니다.이전 솔루션의 데이터를 사용하지만 녹일 필요는 없습니다.

library(ggplot2)

tasks <- c("Review literature", "Mung data", "Stats analysis", "Write Report")
dfr <- data.frame(
  name        = factor(tasks, levels = tasks),
  start.date  = as.Date(c("2010-08-24", "2010-10-01", "2010-11-01", "2011-02-14")),
  end.date    = as.Date(c("2010-10-31", "2010-12-14", "2011-02-28", "2011-04-30")),
  is.critical = c(TRUE, FALSE, FALSE, TRUE)
)

ggplot(dfr, aes(x =start.date, xend= end.date, y=name, yend = name, color=is.critical)) +
  geom_segment(size = 6) +
  xlab(NULL) + ylab(NULL)

갠트 플롯

라이브러리 플롯PrjNetworks는 프로젝트 관리에 유용한 네트워킹 도구를 제공합니다.

library(PlotPrjNetworks)
project1=data.frame(
task=c("Market Research","Concept Development","Viability Test",
"Preliminary Design","Process Design","Prototyping","Market Testing","Final Design",
"Launching"),
start=c("2015-07-05","2015-07-05","2015-08-05","2015-10-05","2015-10-05","2016-02-18",
"2016-03-18","2016-05-18","2016-07-18"),
end=c("2015-08-05","2015-08-05","2015-10-05","2016-01-05","2016-02-18","2016-03-18",
"2016-05-18","2016-07-18","2016-09-18"))
project2=data.frame(
from=c(1,2,3,4,5,6,7,8),
to=c(2,3,4,5,6,7,8,9),
type=c("SS","FS","FS","SS","FS","FS","FS","FS"),
delay=c(7,7,7,8,10,10,10,10))
GanttChart(project1,project2)

enter image description here

각 작업에 대해 여러 개의 막대를 사용하여 ggplot-Answer를 개선하고자 합니다.

먼저 일부 데이터를 생성합니다(dfRP는 다른 답변의 data.fr이고 dfrR은 실현 날짜가 있는 다른 data.frame이며 mdfr은 다음 ggplot()-문에 병합 적합합니다).

library(reshape2)
tasks <- c("Review literature", "Mung data", "Stats analysis", "Write Report")
dfrP <- data.frame(
  name        = factor(tasks, levels = tasks),
  start.date  = as.Date(c("2010-08-24", "2010-10-01", "2010-11-01", "2011-02-14")),
  end.date    = as.Date(c("2010-10-31", "2010-12-14", "2011-02-28", "2011-04-30")),
  is.critical = c(TRUE, FALSE, FALSE, TRUE)
)
dfrR <- data.frame(
  name        = factor(tasks, levels = tasks),
  start.date  = as.Date(c("2010-08-22", "2010-10-10", "2010-11-01", NA)),
  end.date    = as.Date(c("2010-11-03", "2010-12-22", "2011-02-24", NA)),
  is.critical = c(TRUE, FALSE, FALSE,TRUE)
)
mdfr <- merge(data.frame(type="Plan", melt(dfrP, measure.vars = c("start.date", "end.date"))),
  data.frame(type="Real", melt(dfrR, measure.vars = c("start.date", "end.date"))), all=T)

이제 작업 이름의 면을 사용하여 이 데이터를 플롯합니다.

library(ggplot2)
ggplot(mdfr, aes(x=value, y=type, color=is.critical))+
  geom_line(size=6)+
  facet_grid(name ~ .) +
  scale_y_discrete(limits=c("Real", "Plan")) +
  xlab(NULL) + ylab(NULL)

is.critical-information이 없으면 Plan/Real을 색상으로 사용할 수도 있지만(내가 선호하는 경우), 다른 답변의 data.frame을 사용하여 비교하기를 원했습니다.

당신은 이 게시물을 볼 수 있습니다.R 및 gg 그림을 사용합니다.

https://dwh-businessintelligence.blogspot.nl/2016/05/what-if-for-project-management.html

r and ggplot Gantt chart

언급URL : https://stackoverflow.com/questions/3550341/gantt-charts-with-r