[R] Gantt Chart Using Plotrix

bbb_@@@ m@iii@g oii verizo@@@et bbb_@@@ m@iii@g oii verizo@@@et
Mon Apr 23 01:50:30 CEST 2018


Hi Sarah

Thank you very much for your pointers.

Is there a way to specify the date string as POSIXct when reading in? 

I have tried the following (very inelegant way) and still have no luck.

--- Begin Code ---

# 1st read in the spreadsheet with stringsAsFactors set to FALSE

> abc <- read.csv("gntr1.csv", header=TRUE, stringsAsFactors=FALSE)
> abc
  code tasks.labels      start        end depends done
1  101       task 1 2018-04-01 2018-04-15     101  100
2  102        task2 2018-04-15 2018-05-31     101   50
3  103       task 3 2018-06-01 2018-06-30     102    0


 # Next convert the date strings to POSIXct format:
 # The Idea here is to take each of the individual columns in the spreadsheet
 # and convert them to the required format and then assemble the dataframe back again:
 
 
> c1d1 <- abc$tasks.labels
> c1d1
[1] "task 1" "task2"  "task 3"
> c2d1 <- as.POSIXct(abc$start)
> c2d1
[1] "2018-04-01 EDT" "2018-04-15 EDT" "2018-06-01 EDT"
> c3d1 <- as.POSIXct(abc$end)
> c3d1
[1] "2018-04-15 EDT" "2018-05-31 EDT" "2018-06-30 EDT"
> cdfg <- data.frame(c1d1,c2d1,c3d1)
> cdfg
    c1d1       c2d1       c3d1
1 task 1 2018-04-01 2018-04-15
2  task2 2018-04-15 2018-05-31
3 task 3 2018-06-01 2018-06-30


# But still no luck !

> gantt.chart(cdfg)
Error in `$<-.data.frame`(`*tmp*`, "priorities", value = numeric(0)) : 
  replacement has 0 rows, data has 3
> str(cdfg)
'data.frame':   3 obs. of  3 variables:
 $ c1d1: Factor w/ 3 levels "task 1","task 3",..: 1 3 2
 $ c2d1: POSIXct, format: "2018-04-01" "2018-04-15" "2018-06-01"
 $ c3d1: POSIXct, format: "2018-04-15" "2018-05-31" "2018-06-30"
> dput(cdfg)
structure(list(c1d1 = structure(c(1L, 3L, 2L), .Label = c("task 1", 
"task 3", "task2"), class = "factor"), c2d1 = structure(c(1522555200, 
1523764800, 1527825600), class = c("POSIXct", "POSIXt"), tzone = ""), 
    c3d1 = structure(c(1523764800, 1527739200, 1530331200), class = c("POSIXct", 
    "POSIXt"), tzone = "")), .Names = c("c1d1", "c2d1", "c3d1"
), row.names = c(NA, -3L), class = "data.frame")
> 

----- End Code ---


Thank you and Regards
Indr





-----Original Message-----
From: Sarah Goslee <sarah.goslee using gmail.com>
To: bbb_aaa <bbb_aaa using verizon.net>
Cc: David Winsemius <dwinsemius using comcast.net>; r-help <r-help using r-project.org>
Sent: Sun, Apr 22, 2018 6:30 pm
Subject: Re: [R] Gantt Chart Using Plotrix

Hi,

The help file for gantt.chart states that dates must be in POSIXct
format, and the example shows how to do that. There's no reason that I
can see that you can't use a data frame as input to gantt.chart, but
you need to be very careful that your data frame matches the correct
format. I bet also that your character fields were imported as
factors, because you didn't specify not to.

Try running the first couple lines of the example code, then compare

str(abc)

with

str(gantt.info)

and adjust the format of your dataset as necessary.

If you still can't figure it out, then use dput(abc) to provide a
reproducible example, and submit that to the list. We can't tell the
format of the various columns from a copy and paste.

Sarah

On Sun, Apr 22, 2018 at 6:10 PM,  <bbb_aaa using verizon.net> wrote:
> From the help file for plotrix:
> "  ... x - a list of task labels, start/end times and task priorities as returned by get.gantt.info ..."
>
> So I try to create an object that will contain this information.
>
> abc <- read.csv("gntr1a.csv")
>
> # The above csv file was generated from MS .xlsx file containing the tasks and corresponding dates
>
>> abc
>   code tasks.labels      start        end depends done
> 1  101       task 1 2018/04/01 2018/04/15      NA  100
> 2  102 task2 2018/04/15 2018/05/31     101   50
> 3  103       task 3 2018/06/01 2018/06/30     102    0
>> gantt.chart(abc)
> Error in `$<-.data.frame`(`*tmp*`, priorities, value = numeric(0)) :
>   replacement has 0 rows, data has 3
>>
>
> Manually adding the required tasks and dates (as given in the help file example) is not practical for my situation ....
>
>
>
>
>
> -----Original Message-----
> From: David Winsemius <dwinsemius using comcast.net>
> To: bbb_aaa <bbb_aaa using verizon.net>
> Cc: r-help <r-help using r-project.org>
> Sent: Sun, Apr 22, 2018 4:31 pm
> Subject: Re: [R] Gantt Chart Using Plotrix
>
>
>> On Apr 22, 2018, at 11:50 AM, bbb_aaa using verizon.net wrote:
>>
>> Hi
>>
>> I am trying to generate a complex Gantt chart using the gantt.chart function in the plotrix package.
>>
>> Ideally I would like to use a spreadsheet to populate the activities (tasks) and start and end dates that this function expects and then export the spreadsheet file as a .CSV text file so I can read in this file to generate the gantt chart. Reading through the help file I have not been able to see what exactly this spreadsheet should like. The example provided with the "gantt.chart" function seems to indicate all the information needs to be hand coded. Because of the complexity of my chart this is not only very error prone but also is impractical.
>>
>> Can anyone help me with this? There is also a "get.gantt.info" function for creating a gantt object but the help on this is almost next to nothing !
>>
>> Any help you can provide on this would be great.
>>
>> There is another R package called "plan" which is very user friendly but for my purpose this doesn't have all the functionality I am looking for.
>
> The method to generate the most interest and attention to a question is to post a reproducible example with a clear description of the desired "functionality".
>
>>
>> Thanks
>> indr
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> David Winsemius
> Alameda, CA, USA
>
> 'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law
>

-- 
Sarah Goslee
http://www.functionaldiversity.org




More information about the R-help mailing list