ggplot2 applies transformations at various points in the process of
training a ggplot, in the following order:
scale transformations (effected by scale_ functions);
statistical transformations (effected by stat_ functions);
coordinate transformations (effected by coord_ functions).
geom_bar() calls stat_bin(), so the bar plots occur after statistical
transformation. Thus, when you use scale_y_sqrt(), it transforms the
y's before passing it to stat_bin(), which is why you don't get what
you expected.
OTOH, coordinate scaling takes place after statistical transformation,
so a coordinate change affects both the y-scale and the bars. So the
following code does what you expected:
d <- data.frame(x=factor(c(1,1,2)), y=c(1,2,3), fill=factor(c(1,2,3)))
library(ggplot2)
ggplot(d, aes(x = x, fill = fill)) +
geom_bar(aes(y = y), stat = "identity", position = "stack") +
coord_trans(y = "sqrt")
This ordering is documented in both the first and second editions of
Hadley's ggplot2 book, the latter of which is forthcoming. To answer
your question, the behavior is not a bug - it's a design feature of
which you were apparently unaware.
Notice that the ggvis() call uses trans = inside scale_numeric(); it
borrows from ggplot2::coord_trans().
Dennis
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
>
https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
ggplot2+u...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.