Faceting: can I change panel heights individually?

14 views
Skip to first unread message

Roberto

unread,
Sep 2, 2009, 4:08:30 PM9/2/09
to ggplot2
I'm trying again since I got no response to the message titled "Scales
and space in faceting".

Is there a way to have individual control for the panel heights in
faceting? I could use such a feature since I get unpredictable
behavior when using scales="free", space="free".

According to the documentation in Chapter 7,
"For facet_grid there is an additional parameter called space, which
takes values "free" or "fixed". When the space can vary freely, each
column (or row) will have width (or height) proportional to the range
of the scale for that column (or row)."

It seems to work as documented when space = "free" and scales =
"fixed" (in this case the same scale is used in all panels) but not
when scales = "free". Take the following example:

da <- data.frame(
     x=rep(1:5, 2),
     y=c(1+(0:4), 1+(0:4)/10),
     z=rep(1:2, each=5))
da

#   x   y z
#1  1 1.0 1
#2  2 2.0 1
#3  3 3.0 1
#4  4 4.0 1
#5  5 5.0 1
#6  1 1.0 2
#7  2 1.1 2
#8  3 1.2 2
#9  4 1.3 2
#10 5 1.4 2

qplot(x, y, data=da, group=z, geom="line") +
#    scale_y_log10() +
     facet_grid(z~., scales="free_y", space="free")

If the facet heights were proportional to their row ranges, the ratio
of the top to bottom facet heights (i.e., z=1 to z=2) would be (5-1)/
(1.4-1) = 4/0.4 = 10. The observed ratio in the resulting plot is
instead a lot smaller than that.

If you uncomment the line with scale_y_log10() the heights ratio would
be log10(5)/log10(1.4) (since log10(1) = 0), i.e., 4.78. In reality,
the two panel heights look the same in my display!

I'm using R 2.9.1 and ggplot2 0.8.3.

Roberto

hadley wickham

unread,
Sep 4, 2009, 2:27:03 PM9/4/09
to Roberto, ggplot2
> I'm trying again since I got no response to the message titled "Scales
> and space in faceting".

Sorry, I get a lot of email, and I tend not to reply when I'm doing
research/trying to get bigger things done. I promise I will always
reply eventually.

> Is there a way to have individual control for the panel heights in
> faceting? I could use such a feature since I get unpredictable
> behavior when using scales="free", space="free".

No unfortunately not. If someone could come up with a good syntax for
this I could think about supporting it, but it's hard to come up with
a good general way of describing the sizes.

Hadley

--
http://had.co.nz/

Nicholas Lewin-Koh

unread,
Sep 4, 2009, 3:58:46 PM9/4/09
to ggplot2
Hi,
Is anyone working on anything like latticist for ggplot2?
While to do serious graphics more control is necessary, for getting
non R users into ggplot that would be useful. So before I reinvent
the wheel, anyone on this already?

Nicholas

Reply all
Reply to author
Forward
0 new messages