setting boxplot x-axis positions

726 views
Skip to first unread message

Nick S

unread,
Dec 2, 2011, 1:23:20 PM12/2/11
to ggp...@googlegroups.com
Hi,

I have data with progressively fewer observations as x increases. I've constructed boxplot with breaks based on quantiles of the data so that I have roughly the same number of observations per box, thus the bin widths become steadily larger. When I plot the boxplot, the boxes are all placed right next to each other (since they are factors), but this obscures the bin width differences, and the underlying break locations. How can I space out the boxes so that, say, the left breakpoint of each corresponds to the location on the x-axis in cartesian coordinates?

Thank you in advance for your help,
Nick

Winston Chang

unread,
Dec 2, 2011, 3:07:47 PM12/2/11
to ggp...@googlegroups.com
I'm not sure this is what you're looking for, but you can use a continuous x axis for box plots, if you specify grouping.

set.seed(111)
dat <- data.frame(x=rnorm(50,sd=1.5)^2, y= rnorm(50))

ggplot(dat,aes(x=x,y=y)) + geom_boxplot(aes(group=floor(sqrt(x)))) + 
    geom_point(shape=19)

One drawback is that the width of each box is the width of the actual data, which can be smaller than the group size. I don't know if there's a way around this.

-Winston






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

test.png

Nick S

unread,
Dec 2, 2011, 3:37:10 PM12/2/11
to ggp...@googlegroups.com
Thank you, Winston, your suggestion got me on the right track!

Reply all
Reply to author
Forward
0 new messages