Skip to content

Commit fd66a9f

Browse files
committed
Tweak docs for plot basics
1 parent 56e8612 commit fd66a9f

File tree

6 files changed

+113
-126
lines changed

6 files changed

+113
-126
lines changed

R/aes.r

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,21 @@ NULL
2222
"max" = "ymax"
2323
)
2424

25-
#' Define aesthetic mappings.
25+
#' Construct aesthetic mappings
2626
#'
27-
#' Generate aesthetic mappings that describe how variables in the data are
28-
#' mapped to visual properties (aesthetics) of geoms. This function also
29-
#' standardise aesthetic names by performs partial name matching, converting
30-
#' color to colour, and old style R names to ggplot names (eg. pch to shape,
31-
#' cex to size)
27+
#' Aesthetic mappings describe how variables in the data are mapped to visual
28+
#' properties (aesthetics) of geoms. Aesthetic mappings can be set in
29+
#' \code{\link{ggplot2}} and in individual layers.
30+
#'
31+
#' This function also standardise aesthetic names by performing partial
32+
#' matching, converting color to colour, and translating old style R names to
33+
#' ggplot names (eg. pch to shape, cex to size)
3234
#'
3335
#' @param x,y,... List of name value pairs giving aesthetics to map to
34-
#' variables. The names for x and y aesthetics can be omitted (because
35-
#' they are so common); all other aesthetics must be named.
36-
#' @seealso See \code{\link{aes_q}}/\code{\link{aes_string}} for standard
37-
#' evaluation versions of \code{aes}.
38-
#' @seealso See
39-
#' \code{\link{aes_colour_fill_alpha}}, \code{\link{aes_group_order}},
40-
#' \code{\link{aes_linetype_size_shape}} and \code{\link{aes_position}}
41-
#' for more specific examples with different aesthetics.
36+
#' variables. The names for x and y aesthetics are typically omitted because
37+
#' they are so common; all other aesthetics must be named.
38+
#' @seealso See \code{\link{aes_}} for a version of \code{aes} that is
39+
#' more suitable for programming with.
4240
#' @export
4341
#' @examples
4442
#' aes(x = mpg, y = wt)

R/plot.r

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
#' Create a new ggplot plot.
1+
#' Create a new ggplot
22
#'
33
#' \code{ggplot()} initializes a ggplot object. It can be used to
44
#' declare the input data frame for a graphic and to specify the
55
#' set of plot aesthetics intended to be common throughout all
66
#' subsequent layers unless specifically overridden.
77
#'
8-
#' \code{ggplot()} is typically used to construct a plot
9-
#' incrementally, using the + operator to add layers to the
10-
#' existing ggplot object. This is advantageous in that the
11-
#' code is explicit about which layers are added and the order
12-
#' in which they are added. For complex graphics with multiple
13-
#' layers, initialization with \code{ggplot} is recommended.
8+
#' \code{ggplot()} is used to construct the initial plot object,
9+
#' and is almost always followed by \code{+} to add component to the
10+
#' plot. There are three common ways to invoke \code{ggplot}:
11+
#'
12+
#' \enumerate{
13+
#' \item \code{ggplot(df, aes(x, y, <other aesthetics>))}
14+
#' \item \code{ggplot(df)}
15+
#' \item \code{ggplot()}
16+
#' }
1417
#'
15-
#' There are three common ways to invoke \code{ggplot}:
16-
#' \itemize{
17-
#' \item \code{ggplot(df, aes(x, y, <other aesthetics>))}
18-
#' \item \code{ggplot(df)}
19-
#' \item \code{ggplot()}
20-
#' }
2118
#' The first method is recommended if all layers use the same
2219
#' data and the same set of aesthetics, although this method
2320
#' can also be used to add a layer using data from another
@@ -42,51 +39,52 @@
4239
#' to using the environment in which \code{ggplot()} is called.
4340
#' @export
4441
#' @examples
45-
#' df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),
46-
#' y = rnorm(30))
47-
#' # Compute sample mean and standard deviation in each group
42+
#' # Generate some sample data, then compute mean and standard deviation
43+
#' # in each group
44+
#' df <- data.frame(
45+
#' gp = factor(rep(letters[1:3], each = 10)),
46+
#' y = rnorm(30)
47+
#' )
4848
#' ds <- plyr::ddply(df, "gp", plyr::summarise, mean = mean(y), sd = sd(y))
4949
#'
50-
#' # Declare the data frame and common aesthetics.
51-
#' # The summary data frame ds is used to plot
52-
#' # larger red points in a second geom_point() layer.
53-
#' # If the data = argument is not specified, it uses the
54-
#' # declared data frame from ggplot(); ditto for the aesthetics.
55-
#' ggplot(df, aes(x = gp, y = y)) +
56-
#' geom_point() +
57-
#' geom_point(data = ds, aes(y = mean),
58-
#' colour = 'red', size = 3)
50+
#' # The summary data frame ds is used to plot larger red points on top
51+
#' # of the raw data. Note that we don't need to supply `data` or `mapping`
52+
#' # in each layer because the defaults from ggplot() are used.
53+
#' ggplot(df, aes(gp, y)) +
54+
#' geom_point() +
55+
#' geom_point(data = ds, aes(y = mean), colour = 'red', size = 3)
56+
#'
5957
#' # Same plot as above, declaring only the data frame in ggplot().
6058
#' # Note how the x and y aesthetics must now be declared in
6159
#' # each geom_point() layer.
6260
#' ggplot(df) +
63-
#' geom_point(aes(x = gp, y = y)) +
64-
#' geom_point(data = ds, aes(x = gp, y = mean),
65-
#' colour = 'red', size = 3)
66-
#' # Set up a skeleton ggplot object and add layers:
61+
#' geom_point(aes(gp, y)) +
62+
#' geom_point(data = ds, aes(gp, mean), colour = 'red', size = 3)
63+
#'
64+
#' # Alternatively we can fully specify the plot in each layer. This
65+
#' # is not useful here, but can be more clear when working with complex
66+
#' # mult-dataset graphics
6767
#' ggplot() +
68-
#' geom_point(data = df, aes(x = gp, y = y)) +
69-
#' geom_point(data = ds, aes(x = gp, y = mean),
70-
#' colour = 'red', size = 3) +
71-
#' geom_errorbar(data = ds, aes(x = gp, y = mean,
72-
#' ymin = mean - sd, ymax = mean + sd),
73-
#' colour = 'red', width = 0.4)
68+
#' geom_point(data = df, aes(gp, y)) +
69+
#' geom_point(data = ds, aes(gp, mean), colour = 'red', size = 3) +
70+
#' geom_errorbar(
71+
#' data = ds,
72+
#' aes(gp, mean, ymin = mean - sd, ymax = mean + sd),
73+
#' colour = 'red',
74+
#' width = 0.4
75+
#' )
7476
ggplot <- function(data = NULL, mapping = aes(), ...,
7577
environment = parent.frame()) {
7678
UseMethod("ggplot")
7779
}
7880

7981
#' @export
80-
#' @rdname ggplot
81-
#' @usage NULL
8282
ggplot.default <- function(data = NULL, mapping = aes(), ...,
8383
environment = parent.frame()) {
8484
ggplot.data.frame(fortify(data, ...), mapping, environment = environment)
8585
}
8686

8787
#' @export
88-
#' @rdname ggplot
89-
#' @usage NULL
9088
ggplot.data.frame <- function(data, mapping = aes(), ...,
9189
environment = parent.frame()) {
9290
if (!missing(mapping) && !inherits(mapping, "uneval")) {

R/save.r

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,18 @@
77
#'
88
#' @param filename File name to create on disk.
99
#' @param plot Plot to save, defaults to last plot displayed.
10-
#' @param device Device to use (function or any of the recognized extensions,
11-
#' e.g. \code{"pdf"}). By default, extracted from filename extension.
12-
#' \code{ggsave} currently recognises eps/ps, tex (pictex), pdf, jpeg, tiff,
13-
#' png, bmp, svg and wmf (windows only).
10+
#' @param device Device to use. Can be either be a device function
11+
#' (e.g. \code{\link{png}}), or one of "eps", "ps", "tex" (pictex),
12+
#' "pdf", "jpeg", "tiff", "png", "bmp", "svg" or "wmf" (windows only).
1413
#' @param path Path to save plot to (combined with filename).
1514
#' @param scale Multiplicative scaling factor.
16-
#' @param width,height Plot dimensions, defaults to size of current graphics
17-
#' device.
18-
#' @param units Units for width and height when specified explicitly (in, cm,
19-
#' or mm)
20-
#' @param dpi Resolution used for raster outputs.
15+
#' @param width,height,units Plot size in \code{units} ("in", "cm", or "mm").
16+
#' If not supplied, uses the size of current graphics device.
17+
#' @param dpi Plot resolution. Applies only to raster output types.
2118
#' @param limitsize When \code{TRUE} (the default), \code{ggsave} will not
2219
#' save images larger than 50x50 inches, to prevent the common error of
2320
#' specifying dimensions in pixels.
24-
#' @param ... Other arguments passed on to graphics device
21+
#' @param ... Other arguments passed on to graphics \code{device}.
2522
#' @export
2623
#' @examples
2724
#' \dontrun{

man/aes.Rd

Lines changed: 13 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ggplot.Rd

Lines changed: 37 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ggsave.Rd

Lines changed: 7 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)