dankelley / plan

R package for project planning
https://dankelley.github.io/plan/
33 stars 9 forks source link

handling multiple start/end dates for same line for gannt chart #29

Closed daniellenewby closed 1 year ago

daniellenewby commented 1 year ago

Hi Dan,

I was wondering if i could get some help and your expertise on this please? I would like to have multiple start and end dates on my gannt chart for one line. In my example screenshot below you can see that there are 3 lines for PPI with different start and end dates. I would like there to be one line called PPI but these multiple boxes on the same line. I tried the suggestion from a previous closed issue but this did not appear to work with the example https://github.com/dankelley/plan/issues/2

Is there any other workaround you think i could try? What would be great is that when you add a task you can specify sets of start and end dates so for example g <- ganttAddTask(g, "PPI", c("2000-01-01", "2001-01-01", "2002-01-01"), c("2000-02-01", "2001-02-01", "2002-02-01"), done = 100)

I have posted the code below and thanks for any help! image

library(plan)
g <- new("gantt")
g <- ganttAddTask(g, "Study 1: Characterisation")
g <- ganttAddTask(g, "Data curation", "2000-01-01", "2000-03-01", done = 100)
g <- ganttAddTask(g, "Characterisation", "2000-03-01", "2000-09-01", done = 100)
g <- ganttAddTask(g, "Writeup", "2000-09-01", "2000-11-01", done = 100)

g <- ganttAddTask(g, "Study 2: Identifying Subtypes")
g <- ganttAddTask(g, "Clustering", "2000-11-01", "2001-01-01", done = 100)
g <- ganttAddTask(g, "Validation of clusters", "2001-01-01", "2001-03-01", done = 100)
g <- ganttAddTask(g, "Writeup", "2001-03-01", "2001-05-01", done = 100)

g <- ganttAddTask(g, "Study 3: Mendelian randomization")
g <- ganttAddTask(g, "Genetic instrument selection", "2001-06-01", "2001-09-01", done = 100)
g <- ganttAddTask(g, "MR analysis", "2001-09-01", "2002-01-01", done = 100)
g <- ganttAddTask(g, "Writeup", "2002-10-01", "2003-01-01", done = 100)

g <- ganttAddTask(g, "Study 4: Improving diagnostics")
g <- ganttAddTask(g, "Validation of existing tools", "2001-06-01", "2001-09-01", done = 100)
g <- ganttAddTask(g, "Extending existing tools", "2001-09-01", "2002-01-01", done = 100)
g <- ganttAddTask(g, "Model validation", "2002-01-01", "2002-04-01", done = 100)
g <- ganttAddTask(g, "Writeup", "2002-10-01", "2003-01-01", done = 100)

g <- ganttAddTask(g, "Training & Development")
g <- ganttAddTask(g, "Leadership & project management", "2001-06-01", "2001-09-01", done = 100)
g <- ganttAddTask(g, "Mendelian randomization", "2001-09-01", "2002-01-01", done = 100)
g <- ganttAddTask(g, "Engagement & Dissemination")
g <- ganttAddTask(g, "PPI", "2002-01-01","2002-02-01", done = 100)
g <- ganttAddTask(g, "PPI", "2001-01-01","2001-02-01", done = 100)
g <- ganttAddTask(g, "PPI", "2000-01-01","2000-02-01", done = 100)
g <- ganttAddTask(g, "Publication submissions", "2002-01-01", "2002-04-01", done = 100)
g <- ganttAddTask(g, "Conference attendance", "2002-01-01", "2002-04-01", done = 100)

plan::plot(g,
           ylabel = list(font = ifelse(is.na(g[["start"]]), 2, 1)),
           event.time = c("2001-01-01", "2002-01-01"),
           xlim = c("2000-01-01", "2003-01-01"),
           col.done = c("#00468BFF", "#00468BFF","#00468BFF", "#00468BFF",
                        "#ED0000FF","#ED0000FF", "#ED0000FF","#ED0000FF",
                        "#42B540FF", "#42B540FF","#42B540FF","#42B540FF",
                        "#0099B4FF", "#0099B4FF","#0099B4FF","#0099B4FF","#0099B4FF",
                        "#925E9FFF", "#925E9FFF","#925E9FFF","#925E9FFF"

                        ),
           #col.notdone = c("red"),
           axes  = TRUE, 
           #las=2,
           maiAdd=c(0.5,0,0,0),
           time.format = paste((seq(0, 36, by = 3)), sep = "") 
)

line <- 1.75 # adjust this
mtext("Months", side=1, line=line, at = 0.75)
dankelley commented 1 year ago

Hi Danielle,

I had a look at the code, and altering it to take vectors for things like start/end times would be a bit tricky. Right now, such things are stored in a vector, with one item for each item created with ganttAddTask(). I just tried storing these things in a list structure instead of a vector, and there are quite a lot of ripple effects to consider, and it's a bit hard to see how to fix them. (The code is something like 700 lines long.)

I never thought to permit this because I was thinking that tasks could be considered separate, e.g. your PPI things might be "PPI stage 1", "PPI stage 2" or whatever. (Sorry, I don't know what words to use because I've not heard of PPI as an acronym before.)

Sorry I can't be of more help.

daniellenewby commented 1 year ago

Hey Dan, not to worry! just thought i would ask if it was possible :) The PPI are patient public involvement meetings and they occur at different points over time but you are right i can alway put meeting 1, 2 3 etc thanks for your quick response!