> On Thu, Oct 14, 2010 at 15:02, Jon Olav Vik <
jono...@gmail.com> wrote:
> > Can I eliminate the gap between neighbouring stacks of bars in this
> > example?
>
> > dplot <- ggplot(diamonds, aes(clarity, fill = cut))
> > dplot + geom_bar(position = "stack")
On Oct 14, 4:10 pm, Brandon Hurr <
bhiv...@gmail.com> wrote:
> It's pretty ugly, but...
>
> dplot + geom_bar(width=1)
Thank you! I knew I'd seem such an option before, but couldn't find it
in ?geom_bar 8-)
Even with the "width" argument, I needed to debug a bit before it
worked. I describe my case here for posterity:
My actual data frame was a molten crosstabulation, like this:
> df <- read.table(header=TRUE, textConnection("
Species variable value
Apple Fat 0.1
Orange Fat 0.2
Apple Protein 0.2
Orange Protein 0.4
Apple Carbo 0.7
Orange Carbo 0.4
"))
The final solution was this:
> ggplot(df) + geom_bar(aes(x=Species, y=value, fill=variable), width=1)
This line below is what I started with. I didn't realize that
stat="identity" is superfluous when both x and y are given. Also,
stacking seems to be the default.
> ggplot(df) + geom_bar(aes(x=Species, y=value, fill=variable), stat="identity", position="stack")
Adding "width" to the latter command has no effect; the argument is
just ignored.
> ggplot(df) + geom_bar(aes(x=Species, y=value, fill=variable), stat="identity", position="stack", width=1)
I guess the reason I don't need stat_identity is that I have only one
row per "Species" and "variable". The default aggregation seems to be
averaging (ggplot(rbind(df, df)) + ... looks identical to ggplot(df)
+ ...), so that the data pass through unchanged.
Thank you very much for your help!
Regards,
Jon Olav