[R] juxtaposed and stacked bars in one barplot?

Stefan Uhmann stefan.uhmann at mailbox.tu-dresden.de
Thu Aug 28 16:31:53 CEST 2008


hadley wickham schrieb:
> Hi Stefan,
> 
> Could you be a bit more explicit?  Do you have an example dataset that
> you are trying to visualise?
> 

Right, thanks for pointing out the obvious.

So here's my code:

 >>
library(gplots)

quarter <- as.factor(sample(c("Q1", "Q2", "Q3", "Q4"),
         100, replace = TRUE))
year <- as.factor(sample(c(seq(from=2000, to=2008)), 100, replace = TRUE))
category <- as.factor(sample(c(seq(from=1, to=4)), 100, replace = TRUE))
test <- data.frame(quarter, year, category)
table(test$category, test$quarter, test$year)
barplot2(table(test$quarter, test$year),
     beside=T, ylim=c(0,10), main="how to include dim3?")
# inclusion of 3rd dimension does not work:
barplot2(table(test$quarter, test$year, test$category),
     beside=T, ylim=c(0,10), main="how to include dim3?")
<<

I want the barplot to be exactly the same but with the bars stacked (by 
'category'). I got the message from Gaspar, but have not yet tried to 
fit his example to my data.

/Stefan



More information about the R-help mailing list