Re: [R] ggplot facet label font size

From: Walker, Sam <s-walker_at_ti.com>
Date: Thu 10 Aug 2006 - 01:19:36 EST


Thanks for the lattice help Gabor and Deepayan.

These snippets work well. I've only been using R a few months and it and the user community have exceeded my expectations.

Best Regards,
-Sam

-----Original Message-----
From: Deepayan Sarkar [mailto:deepayan.sarkar@gmail.com] Sent: Sunday, August 06, 2006 1:18 AM
To: Walker, Sam
Cc: r-help@stat.math.ethz.ch; Gabor Grothendieck Subject: Re: [R] ggplot facet label font size

On 8/3/06, Walker, Sam <s-walker@ti.com> wrote:
>
> This works OK, but there is some extra spacing between the panels, the
> top axis and the strip on the top, and the left labels and panel.
>
> How can I remove these extra spaces?

This turns out to be surprisingly easy (surprising to me at least):

#########

my.strip <-

    function(which.given, which.panel, var.name, ...) {

    if (which.given == 1 && which.panel[2] == 2)

        strip.default(1, which.panel[1],
                      var.name = var.name[1],
                      ...)

}

my.strip.left <-

    function(which.given, which.panel, var.name, ..., horizontal) {

    if (which.given == 2 && which.panel[1] == 1)

        strip.default(1, which.panel[2],
                      var.name = var.name[2],
                      horizontal = FALSE, ...)
}

histogram(~ tip/total_bill | sex + smoker, tips,

          strip = my.strip,
          strip.left = my.strip.left,
          par.strip.text = list(lines = 0.6),
          par.settings =
          list(layout.heights = list(strip = c(0, 1)),
               layout.widths = list(strip.left = c(1, 0)),
               add.text = list(cex = 0.7)))


#########

The trick of changing two-line strips to one-line strips is not obvious from the documentation (such as it is), it depends on the implementation of strips.

HTH, Deepayan

> I've tried changing various layout.widths settings with no luck. It
> seems the spaces are calculated based on the number of conditioning
> variables, in this case 2 (sex+smoker).
>
>
> Thanks in advance...
> -Sam
>
>
> -----Original Message-----
> From: Gabor Grothendieck [mailto:ggrothendieck@gmail.com]
> Sent: Wednesday, August 02, 2006 6:04 PM
> To: Walker, Sam
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] ggplot facet label font size
>
> On 8/2/06, Walker, Sam <s-walker@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)))
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
http://www.stat.wisc.edu/~deepayan/

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu Aug 10 01:25:24 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 10 Aug 2006 - 02:20:31 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.