Wrapping and resizing facet labels

3,653 views
Skip to first unread message

Bill Harris

unread,
Jul 7, 2010, 12:58:52 PM7/7/10
to ggp...@googlegroups.com

I'm doing a facet_wrap(), where the facet labels come from cells in
production spreadsheets, and those labels are quite long. They came to me
with "\n" characters to force line breaks, but I've eliminated those line
breaks to make the labels easier to print.

Is there a way to have facet_wrap() or facet_grid() wrap individual facet
labels so that I don't lose part of the text? Currently, I only see the
center characters. Before I removed the line break characters, I'd see
the center of each line -- a bit better, but not much.

If they labels are still too long, is there a way to adjust the typeface
size of only the facet labels to get them to fit? I thought I once found
how, but I can't find the reference. On p. 143 of the ggplot2 book, I see
the theme elements, but none seem to match the labels at the top of each
facet.

Thanks,

Bill

Hadley Wickham

unread,
Jul 7, 2010, 2:03:36 PM7/7/10
to Bill Harris, ggp...@googlegroups.com
Hi Bill,

Those labels are called strips. Their width is set to the width of
the panel, and the height to the height of the text element. You'll
probably need to keep the newlines and make the font size smaller with
opts(strip.text.y)

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/

Bill Harris

unread,
Jul 7, 2010, 3:00:24 PM7/7/10
to Hadley Wickham, Bill Harris, ggp...@googlegroups.com
On Wed, July 7, 2010 11:03 am, Hadley Wickham wrote:
> Hi Bill,
>
> Those labels are called strips. Their width is set to the width of
> the panel, and the height to the height of the text element. You'll
> probably need to keep the newlines and make the font size smaller with
> opts(strip.text.y)

Thanks, Hadley. I put the newlines back in, and that fixes most of the
problem.

I tried pg+opts(strip.text.y=40) and pg+opts(strip.text.y=2), and I don't
really see a difference either in an R window or when I process the plots
with R2wd. What are the units of strip.text.y? Is there something else I
might be missing?

Thanks,

Bill


Bill Harris

unread,
Jul 7, 2010, 3:16:37 PM7/7/10
to ggp...@googlegroups.com, Bill Harris, ggp...@googlegroups.com
On Wed, July 7, 2010 11:03 am, Hadley Wickham wrote:
> Hi Bill,
>
> Those labels are called strips. Their width is set to the width of
> the panel, and the height to the height of the text element. You'll
> probably need to keep the newlines and make the font size smaller with
> opts(strip.text.y)

[inadvertently only sent to Hadley; resending it now to the list]

Bill Harris

unread,
Jul 7, 2010, 3:18:12 PM7/7/10
to Bill Harris, ggp...@googlegroups.com, Bill Harris
On Wed, July 7, 2010 12:16 pm, Bill Harris wrote:

> I tried pg+opts(strip.text.y=40) and pg+opts(strip.text.y=2), and I don't
> really see a difference either in an R window or when I process the plots
> with R2wd. What are the units of strip.text.y? Is there something else I
> might be missing?

Incidentally, I had tried theme_update(strip.text.y=20) and then
redisplaying the graphic before. Is that the same as the opts() command?

Bill

Hadley Wickham

unread,
Jul 8, 2010, 1:34:00 AM7/8/10
to Bill Harris, ggp...@googlegroups.com
> Thanks, Hadley.  I put the newlines back in, and that fixes most of the
> problem.
>
> I tried pg+opts(strip.text.y=40) and pg+opts(strip.text.y=2), and I don't
> really see a difference either in an R window or when I process the plots
> with R2wd.  What are the units of strip.text.y?  Is there something else I
> might be missing?

You need:

+ opts(strip.text = theme_theme(size = 2)

See the polishing chapter in the book for more details.

Hadley

Bill Harris

unread,
Jul 8, 2010, 8:11:43 AM7/8/10
to Hadley Wickham, ggp...@googlegroups.com
Hadley Wickham <had...@rice.edu> writes:

> You need:
>
> + opts(strip.text = theme_theme(size = 2)
>
> See the polishing chapter in the book for more details.

Hadley,

Thanks! I'll check it out later this morning.

Bill
--
Bill Harris http://makingsense.facilitatedsystems.com/
Facilitated Systems Everett, WA 98208 USA
http://www.facilitatedsystems.com/ phone: +1 425 374-1845

Reply all
Reply to author
Forward
0 new messages