How to create (vertically) faceted plots in ggplot2 with dynamic heights such that all facets have the same scale?

15 views
Skip to first unread message

Yang Zhang

unread,
Jun 8, 2011, 4:58:20 PM6/8/11
to ggp...@googlegroups.com
I'm trying to create faceted plots where all facets have the same
scale but potentially different sizes. I'm trying the following:

qplot(score, ..count.., data=df, geom='density', position='stack') +
facet_grid(method~., scales='free', space='free')

but I get:

Error in if (length(range) == 1 || diff(range) == 0) { :
missing value where TRUE/FALSE needed

I'm also not sure whether this is what I want - it seems from the
examples in http://had.co.nz/ggplot2/facet_grid.html that
scales='free' allows the scales to vary among the facets, whereas I'd
like them to be fixed. But simply specifying space='free' seems to
have no effect.

Thanks in advance.

Hadley Wickham

unread,
Jun 26, 2011, 7:51:09 PM6/26/11
to Yang Zhang, ggp...@googlegroups.com
It's currently not possible to have un-equaled sized facets, except
for the special case where they're proportional to the scale ranges.

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/

Yang Zhang

unread,
Jun 27, 2011, 3:12:10 AM6/27/11
to Hadley Wickham, ggp...@googlegroups.com
That's actually exactly what I was trying to get. This incantation
ended up working for me:

qplot(score, ..count.., data=df, geom='density', fill=I('black')) +
opts(strip.text.y = theme_text()) +
scale_y_continuous(breaks=seq(0,999,by=50)) +
facet_grid(method~., scale='free', space='free'))

Reply all
Reply to author
Forward
0 new messages