[R] ggplot2: facet_grid with only one level does not display the graph with the facet_grid level in title

Hadley Wickham hadley at rice.edu
Sun Nov 7 17:36:24 CET 2010

This is on my to do list:


On Thu, Oct 28, 2010 at 11:51 AM, Matthew Pettis
<matthew.pettis at gmail.com> wrote:
> Hi All,
> Here is the code that I'll be referring to:
> p <- ggplot(wastran.data, aes(PER_KEY, EVENTS))
> (p <- p +
>    facet_grid( pool.short ~ .) +
>    stat_summary(aes(y=EVENTS), fun.y = sum, geom="line") +
>    opts(axis.text.x = theme_text(angle = 90, hjust=1), title="Events
> (15min.) vs. Time: Facet pool", strip.text.y = theme_text())
> )
> Now, depending on preceding parameters, the 'pool.short' factor variable in
> 'wastran.data' can have one distinct factor level or it can have more than
> one.  When 'pool.short' has more than one factor level, the graph performs
> as I expect, with multiple rows of graphs with the value of the 'pool.short'
> variable displayed on the right-hand side of the graph.  When 'pool.short'
> has only one factor level, the value is NOT displayed on the right-hand
> side.  However, I'd still like it displayed, even though it has only one
> value.
> Can someone tell me how to tweak this code to make it still display when it
> has only 1 factor level?  If this code is unclear, I will be happy to take
> some time and generate an artificial but reproducible self-contained
> example.  I left in the stat_summary layer in this code in case it is
> interfering with the desired output (but I suspect is is superfluous, but I
> am not confident enough to say that with absolute certainty).
> Thanks,
> Matt
>        [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org 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.

Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University

More information about the R-help mailing list