Waterfall plots using ggplot2

231 views
Skip to first unread message

Kim

unread,
Jun 22, 2010, 3:16:24 PM6/22/10
to ggplot2
Hi there,

Is there an easy way to create a waterfall plot using ggplot2?

Here is how I create a waterfall plot without using ggplot2:

absXY= c( -1.0 ,-0.4 ,-0.3, -0.5, -0.2 ,-0.2, -0.5 ,-0.3 ,-0.5 , 0.0 ,
0.0 , -0.3, -0.2 ,-0.6 ,-0.2, -0.2, 0.0, 0.0 ,-0.5, -0.2 ,
0.0 ,-0.3 ,-0.4, -0.8 ,-0.3 , 0.0 , 0.0 , 0.0, -0.5 ,0.0, -0.1 ,
0.0 ,-0.1 ,-0.4, -0.2 ,-1.7 ,-0.8 , 0.0 ,0.0 ,-0.2,
-0.1 ,-0.2 ,-0.3 , -0.3 ,-0.1, 0.0 ,-0.4, -0.1 , 0.0 , 0.0 ,-0.2,
-0.1, -0.5 , 0.2 , 0.6 , 0.7, 0.6 , 1.2, 1.0 , 0.3,
0.8 , 2.0, 0.2 , 0.1 , 1.3 , 0.6, 1.1 , 0.3 , 1.2 , 0.8 , 0.4,
0.3 , 0.3, 0.9 , 0.1, 0.2 ,0.4 , 0.4, 0.2 , 0.4 , 0.9 , 0.5 ,
0.2 , 0.3, 0.5, 0.1 , 1.6 , 1.0, 0.4 , 1.6, 1.2 ,0.5, 0.6 ,
1.1 , 3.8 , 0.8 , 0.2 , 0.5 , 1.1 , 1.7 ,0.4 , 0.2 , 0.4, 1.7 ,
0.2, 0.8 ,0.5, 0.1 , 1.2 , 0.6 , 0.1, 0.4, 0.5 ,0.4 ,0.1 ,
0.3 , 0.1 , 0.3, 0.8 , 0.4, 1.4 ,0.2, 0.1 , 0.4 ,0.1 , 0.8,
0.6 , 0.8 , 0.1 , 0.1, 0.9 , 0.5 ,0.2, 0.9, 0.3, 0.2 , 0.1 ,
0.2 ,0.1, 0.9, 2.6 , 0.3 ,0.6, 0.3 , 0.1 )
sort.absXY= absXY[order(absXY)]
plot(sort.absXY, type='h')
axis(side=3, at=c(0:10)*14.5, label=c(0:10)*10, xlab='% of Cases')

I think that waterfall plots may be preferable to histograms in some
instances because you can easily tell what proportion of individuals
have a value below a certain threshold. Waterfall plots also clearly
distinguish the proportion of people with negative, positive, and 0
values.

I'd like to find a way to create waterfall plots using ggplot2 so that
I can then use ggplot2 to do cooler things, like creating a line
rather than the bars in the current waterfall plot, and having a
separate line for different subgroups, and also to use the faceting
options. I may be able to do all this without using ggplot2, but I
kind of feel like it might be easier in ggplot2.

Thanks a bunch for your help/suggestions,

Kim

Bryan Hanson

unread,
Jun 22, 2010, 3:23:19 PM6/22/10
to Kim, ggplot2
Look here for a recent discussion of just that!

http://learnr.wordpress.com/

Bryan
*************
Bryan Hanson
Acting Chair
Professor of Chemistry & Biochemistry
DePauw University, Greencastle IN USA

Hadley Wickham

unread,
Jun 22, 2010, 5:49:30 PM6/22/10
to Bryan Hanson, Kim, ggplot2
And for the sake of posterity, the full link is
http://learnr.wordpress.com/2010/05/10/ggplot2-waterfall-charts/

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/

Reply all
Reply to author
Forward
0 new messages