Re: [R] Gantt chart like graphics

From: Jim Lemon <jim_at_bitwrit.com.au>
Date: Thu, 29 May 2008 22:30:11 +1000

kljosc wrote:
> Dear R Community,
>
> I have a dataframe like this
>
> dat product1 product2 ... productn
> 01.1.2008 1 1 1
> 02.1.2008 1 1 2
> .
> 15.2.2008 2 2 NA
> .
> 04.4.2008 2 2 1
> 05.4.2008 NA 2 NA
>
> (date ascending order, 1:n products with status 1, 2 or NA)
>
> and want to produce a graphic like this, where 1 or 2 are colored
> rectangles, NAs are white:
>
> product1 11..........2............2_
> product2 11..........2............22
> .
> .
> productn 12.........._............1_
> time_axis (=dat) ->
>
> which looks like a Gantt chart with multiple time slots. I have tried it
> with image() which looks good, but I don't know how to produce an y-axis
> with labels product1, etc. and a x-axis with date labels.
> Further, I want to draw a scatterplot below (using layout()) with the same
> x-axis.
> Maybe someone has a better idea which is easier to label?
>
Hi Klemens,
While this looks like a Gantt chart, you'll have to massage your data a bit to use the gantt.chart function. You would have to define start and end dates. As it looks like your data are in daily increments, it would probably be easier to use plot and mark each occurrence with a square filled with the color corresponding to your productx values. Let's see now, call your dataframe kl.df...

dates<-strptime(kl.df$dat,format="%d.%m.%Y") datesP<-as.POSIXct(dates)
kldim<-dim(kl.df)
plot(0,xlim=range(datesP),ylim=c(1,2),type="n",xaxt="n") axis(1,labels=dates,at=datesP)
for(i in 2:kldim[2])
  points(dates,kl.df[,i],pch=22,bg=kl.df[,i])

pretty rough, but it should give you a start.

Jim



R-help_at_r-project.org mailing list
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. Received on Thu 29 May 2008 - 12:45:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 29 May 2008 - 13:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive