boxplot pre-comupted quantiles

439 views
Skip to first unread message

McCreight

unread,
May 24, 2011, 11:20:36 PM5/24/11
to ggplot2
Hi group-

long story short, it's tremendously more efficient for me to calculate
my boxplot quantiles before plotting (both in terms of memory use and
computing time using multiple cores).

but now that I have my quantiles, I do not see an easy way to get a
ggplot boxplot from them.

## the original data could look like this, were it really at all
possible to store in this way
data0= alply(matrix( rnorm(1000), ncol=10),2)
## and you could plot it up
gg.data0 <- ggplot( melt(data0) ) + geom_boxplot( aes(x=L1, y=value) )
print(gg.data0)

## but my data look like this
data=ldply( alply(matrix( rnorm(1000), ncol=10),2), quantile, c(.05, .
25, .5, .75, .95) )
#> str(data)
#'data.frame': 10 obs. of 6 variables:
# $ .id: chr "1" "2" "3" "4" ...
# $ 5% : num -1.66 -1.58 -1.79 -1.32 -1.63 ...
# $ 25%: num -0.663 -0.533 -0.742 -0.583 -0.668 ...
# $ 50%: num 0.1744 -0.1251 -0.1203 0.0368 -0.1333 ...
# $ 75%: num 0.805 0.764 0.676 0.733 0.494 ...
# $ 95%: num 1.48 1.56 1.4 1.61 1.75 ...

is it possible to get the plot from the data frame "data"??

Thanks!

James

Kohske Takahashi

unread,
May 24, 2011, 11:39:26 PM5/24/11
to McCreight, ggplot2
Hi

try this:

ggplot(data[1:10,], aes(x=.id, ymin=`5%`, lower=`25%`, middle=`50%`,
upper=`75%`, ymax=`95%`)) + geom_boxplot(stat="identity")

--
Kohske Takahashi <takahash...@gmail.com>

Research Center for Advanced Science and Technology,
The University of  Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html

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

Hadley Wickham

unread,
May 25, 2011, 8:15:42 AM5/25/11
to McCreight, ggplot2
FYI make sure your readers know that you're not drawing a traditional boxplot.

Hadley

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

James McCreight

unread,
May 25, 2011, 9:56:13 AM5/25/11
to Hadley Wickham, ggplot2
Thanks!! I knew it had to be trivial. This could be a good one to add to the examples on geom_boxplot(), I dont see any which employ the stat keyword. 

And, yes, these are intended as 90% and 50% confidence intervals for simulations, which will be stated at some point.
Reply all
Reply to author
Forward
0 new messages