Skip to Content
R in a Nutshell, 2nd Edition
book

R in a Nutshell, 2nd Edition

by Joseph Adler
October 2012
Beginner to intermediate
721 pages
21h 38m
English
O'Reilly Media, Inc.
Content preview from R in a Nutshell, 2nd Edition

Quick Plot

As we saw above, the simplest way to use ggplot2 is with the qplot command:

qplot(x, y, ..., data, facets, margins, geom, stat,
  position, xlim, ylim, log, main, xlab, ylab

qplot is designed to pick default values that produce a readable plot (and uses helper functions to help make those choices based on the inputs data), but you can control how qplot works. Here is a description of the arguments to qplot:

ArgumentDescriptionDefault
xX values. 
yY values.NULL
data(Optional) Data frame in which x and y are defined. 
facetsDescribes facets to use as a formula. Uses facet_wrap for one-sided formula or facet_grid for a two sided formula.NULL
marginsEnables displaying margins.FALSE
geomSpecifies the geom to use as a vector of character values."auto"

If x and y are specified, defaults to "point"

If only x is specified, defaults to "histogram"

statSpecifies statistics to use as a vector of character values.list(NULL)
positionSpecifies position adjustments.list(NULL)
xlimLimits for x-axis, as a vector of two values.c(NA,NA)
ylimLimits for y-axis, as a vector of two values.c(NA,NA)
logSpecifies whether to display x-axis, y-axis, or both in log scale. Use "" for neither, "x" for just the x-axis, "y" for just the y-axis, and "xy" for both.""
mainThe title for the plot as a character values.NULL
xlabThe label for the x-axis.deparse(substitute(x))
ylabThe label for the y-axis.deparse(substitute(y))
aspThe y/x aspect ratio.NA
...Other aesthetic attributes passed to lower layers. 
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

R in a Nutshell

R in a Nutshell

Joseph Adler
The R Book, 2nd Edition

The R Book, 2nd Edition

Michael J. Crawley
The R Book

The R Book

Michael J. Crawley
R Packages

R Packages

Hadley Wickham

Publisher Resources

ISBN: 9781449358204Errata Page