Set the space to be free too.
d + geom_bar(stat="identity") +
facet_grid(.~ color, scale="free_x", space="free")
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University
coord_flip() is evil. Wait, that is too harsh. coord_flip() is more
likely to cause problems than it is to solve them. I have a personal
(although practical) vendetta against it.
This is a good example; there is no way to do what you want to do.
space="free" does nothing in the presence of coord_flip(). The
"correct" solution is a geom which draws horizontal bars. See
http://groups.google.com/group/ggplot2/msg/24400aadbbb9bc8e for some
code which can do that. Actually that entire thread
(http://groups.google.com/group/ggplot2/browse_thread/thread/583fcfdced24b483/)
addresses this problem.
> data<- diamonds[1:10,]
> data$cut<- as.factor(as.character(data$cut))
> data$color<- as.factor(as.character(data$color))
> d<- ggplot(data, aes(cut,carat))
> d + geom_bar(stat="identity")+ facet_grid(color~.,scale="free_x",
> space="free")
>
> How could you plot the above example with even bar widths and skipping
> unused factor levels?
> Many thanks!
With the above mentioned custom geom, you could then have
ggplot(data, aes(carat, cut)) +
geom_hbar() +
facet_grid(color ~ ., scale="free_y", space="free")
A caveat: this will surely break with the new ggplot2 0.9.0 that is due
out Any Day Now.