Frequently asked questions - janeshdev/ggplot2 GitHub Wiki

  • Calling qplot in a function or a for loop yields a blank page.

you need to explicitly call the print() method.

  • How do I add a secondary x/y axis?

not possible currently

  • Can I add mathematical / greek letters annotations?

use expression() for x- and y- labels (see ?plotmath). Facet labels have a “labeller” attribute, in particular label_parsed to enable math. expressions. geom_text has a parse attribute (logical) to do the same thing. See plotmath for more details

  • How do I align two (or more) plots?

you can either i) create a dummy factor and make use of the built-in facetting facilities, or, ii) use grid.layout(). See alignTwoPlots for a discussion.

  • How do I pass a variable to ggplot() in a function?

you can use aes_string() to pass variables as character strings.

  • Is it possible to place the strip labels on the left side?

Not currently. See r-help http://www.mail-archive.com/[email protected]/msg105950.html for a hack that might work in some cases.

  • How do I set the x or y limits on a plot?

    • Use scale_y_continuous(limits = c(lower, upper)) or scale_x_continuous(limits = c(lower, upper)) (or their discrete equivalents) if you want the actual data changed or
    • coord_cartesian(xlim = c(lower, upper), ylim = c(lower, upper)) if you just want to "zoom" in or out on a plot.