scale_x_log10() bug with geom="density"

658 views
Skip to first unread message

John St. John

unread,
Nov 8, 2011, 1:20:02 PM11/8/11
to ggp...@googlegroups.com
So here is a density plot like the one I want to make:
ggplot(diamonds, aes(price, colour = cut)) + geom_density()+scale_y_continuous(formatter = "percent")


However my dataset is really scrunched up to the left on the x axis, so I wanted to log scale it so the data is visually distinguishable at the low end. Unfortunately though there seems to be a bug. Notice how the density percentages are no longer true density percentages with this plot:

ggplot(diamonds, aes(price, colour = cut)) + geom_density()+scale_x_log10()+scale_y_continuous(formatter = "percent")

Looking at this I can't really be sure the shape is even right. Is the issue just with the labels on the y axis, or is the density really screwed up when you do the log scaled x axis?

Dennis Murphy

unread,
Nov 8, 2011, 3:44:43 PM11/8/11
to ggp...@googlegroups.com
Compare

ggplot(diamonds, aes(price, colour = cut)) + geom_density()

ggplot(diamonds, aes(log(price), colour = cut)) + geom_density()

You're transforming the horizontal axis scale, so the shapes of the
estimated densities are going to change as well as their values
(heights).

Dennis

> --
> 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
>

Reply all
Reply to author
Forward
0 new messages