[R] ggplot facet label font size

Gabor Grothendieck ggrothendieck at gmail.com
Thu Aug 3 01:03:36 CEST 2006


On 8/2/06, Walker, Sam <s-walker at ti.com> wrote:
> How do I change the font size in the facet labels along the edges of the
> plot?
>
> For example (from the ggplot help file):
>     p<-ggplot(tips, sex ~ smoker, aesthetics=list(x=tip/total_bill))
>     gghistogram(p)
>
> In this plot, the facet labels are "smoker: No", "smoker: Yes", "sex:
> Female", "sex: Male".  What command can I use to reduce the font size of
> these labels?
>
> In lattice terminology, cex is used to scale these strip labels.  But I
> couldn't find the equivalent in ggplot.
>
> The reason I'm asking is I have a 9x7 array of plots which I've been
> plotting with lattice.  I wanted to use ggplot because I like having the
> labels on the edge of the plots

Note that lattice can do that by using custom strip functions:

library(ggplot) # data resides here
library(lattice)

my.strip <- function(which.given, which.panel, ...)
   if (which.given == 1 && which.panel[2] == 2)
      strip.default(which.given, which.panel, ...)

my.strip.left <- function(which.given, which.panel, ..., horizontal)
   if (which.given == 2 && which.panel[1] == 1)
      strip.default(which.given, which.panel, horizontal = FALSE, ...)

histogram(~ tip/total_bill | sex + smoker, tips, strip = my.strip,
     strip.left = my.strip.left, par.settings = list(add.text =
list(cex = 0.7)))



More information about the R-help mailing list