fun with facet labels

659 views
Skip to first unread message

Gray, Wayne

unread,
Mar 16, 2016, 6:44:02 PM3/16/16
to ggplot2
All,

I believe a recent upgrade in ggplot2 is affecting the facet labels in ways that I do not know how to control.

I have attached two plots.

“Rplot_numFix_by_Lvl_nc” used:  facet_wrap(crit.sc ~ sid, ncol=5) to produce the label that I like — namely it has both the “crit.sc” and the “sid” in the header of each plot, with a comma btw the two. NOTE THAT THESE ARE ON THE SAME LINE!! That is good!!

Now — look at the “Rplot_new_plot”. You will see that ggplot is putting each of the two values EACH ON ITS OWN LINE — thereby using TWO lines!! I can no longer study the changes over each facet as they are all smooshed! (tech term for the newbies reading this)!

I used to use this:

+  facet_wrap(crit.sc ~ sid, ncol=4)
and it gave me what I wanted, both values on the same line.
BUT now it puts them each on separate line so that the header is wider than the plot!!

I have played with the “new” (???) labeller feature to no avail!

+  facet_wrap(crit.sc ~ sid, ncol=4, labeller = label_value)
## gives exactly the same result as my original command

+  facet_wrap(crit.sc ~ sid, ncol=4, labeller = label_wrap_gen(width=100)  # still two lines

+  facet_wrap(crit.sc ~ sid, ncol=4, labeller = label_value(multi-line = FALSE) # breaks ggplot


Thanks for any help,

Wayne




Rplot_numFix_by_Lvl_nc.pdf
Rplot_new_plot.pdf

Dennis Murphy

unread,
Mar 17, 2016, 5:15:42 PM3/17/16
to Gray, Wayne, ggplot2
Hi:

The labeller functions have changed in version 2.x.y. What you need is
the .multi_line = FALSE argument in the revised labeller() function.
Here's an example using the mtcars data:

library(ggplot2)

ggplot(mtcars, aes(x = disp, y = mpg)) +
geom_point() +
facet_wrap(~ vs + am, label = labeller(.default = label_both,
.multi_line = FALSE))

Since you wanted label_both() for each strip label, I used it as the default.

Dennis
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Gray, Wayne

unread,
Mar 17, 2016, 8:10:37 PM3/17/16
to Dennis Murphy, ggplot2
Many thanks Dennis. That works!

For my purposes I used “label_value” rather than your suggestion of “label_both”.

+ facet_wrap(crit.sc ~ sid, ncol=4, label = labeller(.default = label_value, .multi_line = FALSE))

“label_value” returned the value for both “crit.sc” (a numeric) and “sid” (a factor), separated by a comma, and both on the same line.
> --
> BEGIN-ANTISPAM-VOTING-LINKS
> ------------------------------------------------------
>
> NOTE: This message was trained as non-spam. If this is wrong,
> please correct the training as soon as possible.
>
> Teach CanIt if this mail (ID 02Qv9fu18) is spam:
> Spam: https://respite.rpi.edu/canit/b.php?i=02Qv9fu18&m=ab3c03227b9b&t=20160317&c=s
> Not spam: https://respite.rpi.edu/canit/b.php?i=02Qv9fu18&m=ab3c03227b9b&t=20160317&c=n
> Forget vote: https://respite.rpi.edu/canit/b.php?i=02Qv9fu18&m=ab3c03227b9b&t=20160317&c=f
> ------------------------------------------------------
> END-ANTISPAM-VOTING-LINKS
>

Reply all
Reply to author
Forward
0 new messages