panel labels in facet_wrap

2,924 views
Skip to first unread message

Alexander Shenkin

unread,
Oct 11, 2011, 5:53:39 PM10/11/11
to ggp...@googlegroups.com
Hi Folks,

Is there any way to change the panel label when using facet_wrap (aside from changing the data in the data frame)?  For example, changing the "0" and "1" below in the titles of the panels?  Apologies if this is a simple answer out there somewhere - searching around didn't come up with anything, but I might have been using the wrong terms.

Thanks,
Allie


Dennis Murphy

unread,
Oct 11, 2011, 6:04:21 PM10/11/11
to Alexander Shenkin, ggp...@googlegroups.com
opts(strip.text.x = ) is what you're looking for, which uses theme_text() to modify horizontal strip labels. See either Chapter 8 of Hadley's book or
https://github.com/hadley/ggplot2/wiki/Faceting-Attributes  (thanks to Brandon Hurr).

HTH,
Dennis

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

bdbbbafb.png

Alexander Shenkin

unread,
Oct 13, 2011, 6:11:56 PM10/13/11
to Dennis Murphy, ggp...@googlegroups.com
Thanks for your reply, Dennis.  I wasn't entirely clear by what I meant by "change" below.  What I'd actually like to do is to change, "0", for example, to "foo".  That is, I don't just want to change the font, color, etc, but rather the string itself.  As far as I can tell, opts(strip.text.x = theme_text()) only gives you access to the display properties of the panel title, not the text of the title itself.

Thanks,
Allie

Dennis Murphy

unread,
Oct 13, 2011, 9:34:17 PM10/13/11
to Alexander Shenkin, ggp...@googlegroups.com
The easiest way to change the strip label is by creating a new factor in the data and using it as the faceting variable. AFAIK, you can't change it on the fly within a ggplot() call.

On Thu, Oct 13, 2011 at 3:11 PM, Alexander Shenkin <ashe...@ufl.edu> wrote:
Thanks for your reply, Dennis.  I wasn't entirely clear by what I meant by "change" below.  What I'd actually like to do is to change, "0", for example, to "foo".  That is, I don't just want to change the font, color, etc, but rather the string itself.  As far as I can tell, opts(strip.text.x = theme_text()) only gives you access to the display properties of the panel title, not the text of the title itself.

That is true. I didn't read the post carefully enough and my response was incorrect...my lapse.

Dennis

Winston Chang

unread,
Sep 20, 2012, 11:37:46 AM9/20/12
to Martin B., ggp...@googlegroups.com, Alexander Shenkin
Hi - I've written a patch for this feature which works, but it won't be merged since it doesn't do things the "right" way. Doing it the right way isn't possible without breaking some things, so it'll have to happen in a future major release of ggplot2.

See the pull request for more info:
https://github.com/hadley/ggplot2/pull/656

-Winston

On Thu, Sep 20, 2012 at 5:26 AM, Martin B. <mar...@webscio.net> wrote:
That works more or less, though when you create a new factor, "expression" labels are not formatted properly, i.e. if I have labels = c(expression(x >= 1)) that is exactly what is shown as the label in the graph, not the nice greater-or-equal sign.. (same applies to greek letters, sub-/superscripts etc.). Any way to make this possible?
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
Reply all
Reply to author
Forward
0 new messages