tags:

views:

46

answers:

1

I want a graph that looks similar to the example given in the lattice docs:

#EXAMPLE GRAPH, not my data
> barchart(yield ~ variety | site, data = barley,
+          groups = year, layout = c(1,6), stack = TRUE, 
+          auto.key = list(points = FALSE, rectangles = TRUE, space = "right"),
+          ylab = "Barley Yield (bushels/acre)",
+          scales = list(x = list(rot = 45))) 

I melted my data to obtain this "long" form dataframe:

> str(MDist)
'data.frame':   34560 obs. of  6 variables:
$ fCycle   : Factor w/ 2 levels "Dark","Light": 2 2 2 2 2 2 2 2 2 2 ...
$ groupname: Factor w/ 8 levels "rowA","rowB",..: 1 1 1 1 1 1 1 1 1 1 ...
$ location : Factor w/ 96 levels "c1","c10","c11",..: 1 1 1 1 1 1 1 1 1 1 ...
$ timepoint: num  1 2 3 4 5 6 7 8 9 10 ...
$ variable : Factor w/ 3 levels "inadist","smldist",..: 1 1 1 1 1 1 1 1 1 1 ...
$ value    : num  0 55.7 75.3 99.2 45.9 73.8 79.3 73.5 69.8 67.6 ...

I want to create a stacked barchart for each groupname and fCycle. I tried this:

barchart(value~timepoint|groupname*fCycle, data=MDist, groups=variable,stack=T) 

It doesn't throw any errors, but it's still thinking after 30 minutes. Is this because it doesn't know how to deal with the 36 values that contribute to each bar? How can I make this data easier for barchart to digest?

+1  A: 

I don't know lattice well, but could it be because your timepoint variable is numeric, not a factor?

JoFrhwld
I tried `barchart(value~factor(timepoint)|groupname*fCycle, data=MDist, groups=variable,stack=T)` with the same lack of result.
dnagirl
Then I'm stumped. This isn't an answer to your question, but I'm pretty sure the `ggplot2` code would be`qplot(factor(timepoint), value, fill = variable, facets = groupname ~ fCycle, geom = "bar", data = MDist)`
JoFrhwld
good idea! So I tried it but it gave me "Error in pmin(y,0): object 'y' not found". And I'm not sure what that means since `y<-MDist$value`
dnagirl
Yeah, I messed up the code. within the `qplot()` add `stat = "identity"` and `position = "stack"`. I think the `position` defaults to `"stack"`, but add it in for good measure.
JoFrhwld
+1 for "there's more than one way to skin a cat"
dnagirl