2222 " max" = " ymax"
2323)
2424
25- # ' Generate aesthetic mappings that describe how variables in the data are
26- # ' mapped to visual properties (aesthetics) of geoms.
25+ # ' Define aesthetic mappings.
2726# '
28- # ' \code{aes} creates a list of unevaluated expressions. This function also
29- # ' performs partial name matching, converts color to colour, and old style R
30- # ' names to ggplot names (eg. pch to shape, cex to size)
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)
3132# '
32- # ' @param x,y,... List of name value pairs giving aesthetics to map.
33+ # ' @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.
3336# ' @family aesthetic generators
3437# ' @seealso See
3538# ' \code{\link{aes_colour_fill_alpha}}, \code{\link{aes_group_order}},
3841# ' @export
3942# ' @examples
4043# ' aes(x = mpg, y = wt)
44+ # ' aes(mpg, wt)
45+ # '
46+ # ' # You can also map aesthetics to functions of variables
4147# ' aes(x = mpg ^ 2, y = wt / cyl)
48+ # '
49+ # ' # Aesthetic names are automatically standarised
50+ # ' aes(col = x)
51+ # ' aes(fg = x)
52+ # ' aes(color = x)
53+ # ' aes(colour = x)
54+ # '
55+ # ' # aes is almost always used with ggplot() or a layer
56+ # ' ggplot(mpg, aes(displ, hwy)) + geom_point()
57+ # ' ggplot(mpg) + geom_point(aes(displ, hwy))
58+ # '
59+ # ' # Aesthetics supplied to ggplot() are used as defaults for every layer
60+ # ' # you can override them, or supply different aesthetics for each layer
4261aes <- function (x , y , ... ) {
43- aes <- structure(as.list(match.call()[- 1 ]), class = " uneval" )
62+ aes <- structure(as.list(match.call()[- 1 ]), class = " uneval" )
4463 rename_aes(aes )
4564}
4665# ' @export
@@ -79,7 +98,7 @@ is_position_aes <- function(vars) {
7998 aes_to_scale(vars ) %in% c(" x" , " y" )
8099}
81100
82- # ' Generate aesthetic mappings from a string/quoted objects
101+ # ' Define aesthetic mappings from a string/quoted objects
83102# '
84103# ' Aesthetic mappings describe how variables in the data are mapped to visual
85104# ' properties (aesthetics) of geoms. \code{\link{aes}} uses non-standard
@@ -97,18 +116,23 @@ is_position_aes <- function(vars) {
97116# ' @export
98117# ' @examples
99118# ' # Threee ways of generating the same aesthetics
100- # ' aes(mpg, wt, col = cyl, fill = NULL )
101- # ' aes_string("mpg", "wt", col = "cyl", fill = NULL )
102- # ' aes_q(quote(mpg), quote(wt), col = quote(cyl), fill = NULL )
119+ # ' aes(mpg, wt, col = cyl)
120+ # ' aes_string("mpg", "wt", col = "cyl")
121+ # ' aes_q(quote(mpg), quote(wt), col = quote(cyl))
103122# '
104- # ' aes(col = cyl, fill = NULL)
105- # ' aes_string(col = "cyl", fill = NULL)
106- # ' aes_q(col = quote(cyl), fill = NULL)
123+ # ' # aes_string and aes_q are most useful when you have the name of a variable
124+ # ' # stored in a variable
125+ # ' var <- "cyl"
126+ # ' aes(col = x)
127+ # ' aes_string(col = var)
128+ # ' aes_q(col = as.name(var))
107129aes_string <- function (x = NULL , y = NULL , ... ) {
108130 mapping <- c(compact(list (x = x , y = y )), list (... ))
109- mapping [vapply(mapping , is.null , logical (1 ))] <- " NULL"
110131
111- parsed <- lapply(mapping , function (x ) parse(text = x )[[1 ]])
132+ parsed <- lapply(mapping , function (x ) {
133+ if (! is.character(x )) return (x )
134+ parse(text = x )[[1 ]]
135+ })
112136 structure(rename_aes(parsed ), class = " uneval" )
113137}
114138
0 commit comments