|
48 | 48 | #' they are so common; all other aesthetics must be named.
|
49 | 49 | #' @seealso [vars()] for another quoting function designed for
|
50 | 50 | #' faceting specifications.
|
| 51 | +#' @return A list with class `uneval`. Components of the list are either |
| 52 | +#' quosures or constants. |
51 | 53 | #' @export
|
52 | 54 | #' @examples
|
53 | 55 | #' aes(x = mpg, y = wt)
|
|
56 | 58 | #' # You can also map aesthetics to functions of variables
|
57 | 59 | #' aes(x = mpg ^ 2, y = wt / cyl)
|
58 | 60 | #'
|
| 61 | +#' # Or to constants |
| 62 | +#' aes(x = 1, colour = "smooth") |
| 63 | +#' |
59 | 64 | #' # Aesthetic names are automatically standardised
|
60 | 65 | #' aes(col = x)
|
61 | 66 | #' aes(fg = x)
|
62 | 67 | #' aes(color = x)
|
63 | 68 | #' aes(colour = x)
|
64 | 69 | #'
|
65 |
| -#' # aes is almost always used with ggplot() or a layer |
| 70 | +#' # aes() is passed to either ggplot() or specific layer. Aesthetics supplied |
| 71 | +#' # to ggplot() are used as defaults for every layer. |
66 | 72 | #' ggplot(mpg, aes(displ, hwy)) + geom_point()
|
67 | 73 | #' ggplot(mpg) + geom_point(aes(displ, hwy))
|
68 | 74 | #'
|
69 |
| -#' # Aesthetics supplied to ggplot() are used as defaults for every layer |
70 |
| -#' # you can override them, or supply different aesthetics for each layer |
71 |
| -#' |
72 |
| -#' |
73 |
| -#' # aes() is a quoting function, so you need to use tidy evaluation |
74 |
| -#' # techniques to create wrappers around ggplot2 pipelines. The |
| 75 | +#' # Tidy evaluation ---------------------------------------------------- |
| 76 | +#' # aes() automatically quotes all its arguments, so you need to use tidy |
| 77 | +#' # evaluation to create wrappers around ggplot2 pipelines. The |
75 | 78 | #' # simplest case occurs when your wrapper takes dots:
|
76 | 79 | #' scatter_by <- function(data, ...) {
|
77 | 80 | #' ggplot(data) + geom_point(aes(...))
|
78 | 81 | #' }
|
79 | 82 | #' scatter_by(mtcars, disp, drat)
|
80 | 83 | #'
|
81 | 84 | #' # If your wrapper has a more specific interface with named arguments,
|
82 |
| -#' # you need to use the "enquote and unquote" technique: |
| 85 | +#' # you need "enquote and unquote": |
83 | 86 | #' scatter_by <- function(data, x, y) {
|
84 |
| -#' ggplot(data) + geom_point(aes(!!enquo(x), !!enquo(y))) |
| 87 | +#' x <- enquo(x) |
| 88 | +#' y <- enquo(y) |
| 89 | +#' |
| 90 | +#' ggplot(data) + geom_point(aes(!!x, !!y)) |
85 | 91 | #' }
|
86 | 92 | #' scatter_by(mtcars, disp, drat)
|
87 | 93 | #'
|
|
0 commit comments