tags:

views:

55

answers:

1

Not sure what I'm doing wrong here. I have this plot:

ggplot(data.PE5, aes(ybands,fill=factor(decide))) + geom_bar(position="dodge") 

which produces:

Then I want to facet by a factor, creating two stacked plots w/ dodged, colored bars

ggplot(data.PE5, aes(ybands,fill=factor(decide))) + geom_bar(position="dodge") + 
facet_grid(~group_label) 

However, I lose the factor-based coloring, which I want to keep:

+1  A: 

If you move the fill into the geom_bar it should work. As:

ggplot(data.PE5, aes(ybands)) + geom_bar(aes(fill=factor(decide)),position="dodge") + facet_grid(~group_label)

The reason is the way ggplot2 builds plots as a grammar (I think).

DrewConway
You shouldn't have to do that - it doesn't matter where you set the fill aesthetic as long as that particular layer inherits or sets it. A reproducible example would be helpful...
hadley