[R] Aggregating date for barplot

Loris Bennett loris.bennett at fu-berlin.de
Thu Dec 10 14:01:35 CET 2009


Hi,

As a first exercise with R, I am misusing it purely as a plotting
tool. I have some data that look like this:

   date     group  dept    cputime
   2008/01  A      phys    124
   2008/01  B      phys    214
   2008/01  C      chem    281
   2008/02  A      phys    092
   2008/02  B      phys    322
   2008/02  C      chem    821
   2008/03  A      phys    678
   2008/03  B      phys    312
   2008/03  C      chem    515
   2008/04  A      phys    302
   2008/04  B      phys    302
   2008/04  C      chem    571
   2008/05  A      phys    452
   2008/05  B      phys    243
   2008/05  C      chem    155
   2008/06  A      phys    230
   2008/06  B      phys    306
   2008/06  C      chem    235

I want to create barplots of CPU time per month for
- individual groups
- individual departments
- all groups  
- all departments  

Currently to get stacked barplot for, say, groups, I am doing: 

   t <- read.table("cpu.dat",header=TRUE)

   a <- subset(t,group=="A")
   b <- subset(t,group=="B")
   c <- subset(t,group=="C")

   m <- rbind(a$cputime,b$cputime,c$cputime)

   n_groups <- length(levels(t$group));

   barplot(m,names.arg=levels(t$date))

Although this works, it strikes me as a little clumsy. In particular,
the creation of the matrix for the barplot seems somewhat inelegant.

I suspect I may be missing something. Does anyone have a better
solution? 

Thanks

Loris

-- 
Dr. Loris Bennett
Computer Centre
Freie Universität Berlin
Berlin, Germany




More information about the R-help mailing list