This should get you started.

> PEL <- read.table("http://r.789695.n4.nabble.com/file/n3981961/example.txt",
header=TRUE, sep="\t")
> PELtable <- with(PEL, tapply(phasetime, data.frame(activity,
as.Date(beg)), sum))
> PELtable
        as.Date.beg.
activity 2010-06-03 2010-06-04 2010-06-05 2010-06-06 2010-06-07
       D       3407      14405      17704      16740       7096
       L       7370      43544      35898      30401         NA
       W       5976      26611      30294      36807      14466
> PELtable[2,5] <- 0
> as.data.frame.table(PELtable)
   activity as.Date.beg.  Freq
1         D   2010-06-03  3407
2         L   2010-06-03  7370
3         W   2010-06-03  5976
4         D   2010-06-04 14405
5         L   2010-06-04 43544
6         W   2010-06-04 26611
7         D   2010-06-05 17704
8         L   2010-06-05 35898
9         W   2010-06-05 30294
10        D   2010-06-06 16740
11        L   2010-06-06 30401
12        W   2010-06-06 36807
13        D   2010-06-07  7096
14        L   2010-06-07     0
15        W   2010-06-07 14466
> barchart(Freq ~ as.Date.beg. , groups=activity,
data=as.data.frame.table(PELtable),
+          stack=TRUE, auto.key=list(reverse=TRUE))
>

You might wish to be more precise in your definition of a 24-hour time
period.  I used calendar date here.
Rich
On Wed, Nov 2, 2011 at 3:24 PM, PEL <pierre-etienne.lessard.1@ulaval.ca>wrote:

> Hello all,
>
> my data looks like this:
>
> "phaseno" / "activity"  / "beg" / "end" / "phasetime"
>
> 1 / "L" / 2010-06-03 19:15:24 / 2010-06-03 21:18:14 / 7370
> 2 / "D" / 2010-06-03 21:18:15 / 2010-06-03 21:19:55 / 100
> 3 / "W" / 2010-06-03 21:19:56 / 2010-06-03 21:22:47 / 171
> 4 / "D" / 2010-06-03 21:22:48 / 2010-06-03 21:23:47 / 59
> 5 / "W" / 2010-06-03 21:23:48 / 2010-06-03 21:23:53 / 5
> 6 / "D" / 2010-06-03 21:23:54 / 2010-06-03 21:26:18 / 144
> 7 / "W" / 2010-06-03 21:26:19 / 2010-06-03 21:32:10 / 351
> 8 / "D" / 2010-06-03 21:32:11 / 2010-06-03 21:32:11 / 0
> 9 / "W" / 2010-06-03 21:32:12 / 2010-06-03 21:32:12 / 0
> 10 / "D" / 2010-06-03 21:32:13 / 2010-06-03 21:32:29 / 16
>
> Please note that phasetime is in seconds and is only a difftime() of "beg"
> and "end".
>
> I want to create a stacked bar chart that gives me the percentage of time
> spent doing every activity (L,D or W) for every 24h period.
> Example: Day 1: 20% =L; 40% = W ; 40% = D.  In a graph obviously.
>
> What I was thinking was dividing my dataframe into several smaller
> dataframes spanning 24h. I tried with by() but I doubt this is the correct
> function. If possible, I would also like to separate a row the phasetime of
> a row if it overlaps two 24 periods.
>
>
> I joined part of my data where *header=TRUE and sep="\t"*
> http://r.789695.n4.nabble.com/file/n3981961/example.txt example.txt
>
> Thank you very much for your time
> PEL
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Creating-barplot-using-time-as-X-tp3981961p3981961.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]

