Google Groups

Re: Stacked ggplot chart does not look accurate.


Hadley Wickham Oct 6, 2010 7:16 PM
Posted in group: ggplot2
Hi Raphael,

How exactly do you expect to stack a bar with a negative height?

Hadley

On Wed, Oct 6, 2010 at 7:15 PM, Raphael <rhv....@gmail.com> wrote:
> Hello everyone!
>
> These data compose the first bar of the graph. Naturally, the sum of
> these four values of C2G equals the y value of the bar (about 14.198):
>> cog[1:4,]
>  Quarter        Segment        C2G
> 1 2008 Q1 Professional D  0.7509433
> 2 2008 Q1 Professional M  7.4151935
> 3 2008 Q1         Home D -0.4347982
> 4 2008 Q1         Home M  6.4669215
>
> This is the code I'm using:
> stackedchart <- ggplot(cog, aes(x=Quarter, y=C2G,
> fill=factor(Segment)))
> stackedchart <- stackedchart + layer(
> geom="bar",
> stat="identity",
> position="stack")
> stackedchart
>
> I expect that the stacked "2008 Q1" bar have four factors each with a
> unique color in this single bar. But the result only has three colors.
> The smallest "Home D" value of -0.435 is missing.
>
> Note that even though the bar only has three visible factors, the
> stacked bar "begins" slightly below the x-axis at y = -0.435. This
> tells me that the negative "Home D" value is included in the
> calculations--it's just not visible.
>
> Why does this happen?
> Is there any way to make it look right?
> Does the resulting warning message "Stacking not well defined when
> ymin != 0" have anything to do with it and, if so, how do I make it
> well defined?
>
> I'm a new R user. Any help you all provide is much appreciated!
>
> -Raphael
>
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/