EVOLUTION-MANAGER
Edit File: aes.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Construct aesthetic mappings</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for aes {ggplot2}"><tr><td>aes {ggplot2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Construct aesthetic mappings</h2> <h3>Description</h3> <p>Aesthetic mappings describe how variables in the data are mapped to visual properties (aesthetics) of geoms. Aesthetic mappings can be set in <code><a href="ggplot.html">ggplot()</a></code> and in individual layers. </p> <h3>Usage</h3> <pre> aes(x, y, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x, y, ...</code></td> <td> <p>List of name-value pairs in the form <code>aesthetic = variable</code> describing which variables in the layer data should be mapped to which aesthetics used by the paired geom/stat. The expression <code>variable</code> is evaluated within the layer data, so there is no need to refer to the original dataset (i.e., use <code>ggplot(df, aes(variable))</code> instead of <code>ggplot(df, aes(df$variable))</code>). The names for x and y aesthetics are typically omitted because they are so common; all other aesthetics must be named.</p> </td></tr> </table> <h3>Details</h3> <p>This function also standardises aesthetic names by converting <code>color</code> to <code>colour</code> (also in substrings, e.g., <code>point_color</code> to <code>point_colour</code>) and translating old style R names to ggplot names (e.g., <code>pch</code> to <code>shape</code> and <code>cex</code> to <code>size</code>). </p> <h3>Value</h3> <p>A list with class <code>uneval</code>. Components of the list are either quosures or constants. </p> <h3>Quasiquotation</h3> <p><code>aes()</code> is a <a href="../../rlang/html/nse-defuse.html">quoting function</a>. This means that its inputs are quoted to be evaluated in the context of the data. This makes it easy to work with variables from the data frame because you can name those directly. The flip side is that you have to use <a href="../../rlang/html/nse-force.html">quasiquotation</a> to program with <code>aes()</code>. See a tidy evaluation tutorial such as the <a href="http://dplyr.tidyverse.org/articles/programming.html">dplyr programming vignette</a> to learn more about these techniques. </p> <h3>See Also</h3> <p><code><a href="vars.html">vars()</a></code> for another quoting function designed for faceting specifications. </p> <h3>Examples</h3> <pre> aes(x = mpg, y = wt) aes(mpg, wt) # You can also map aesthetics to functions of variables aes(x = mpg ^ 2, y = wt / cyl) # Or to constants aes(x = 1, colour = "smooth") # Aesthetic names are automatically standardised aes(col = x) aes(fg = x) aes(color = x) aes(colour = x) # aes() is passed to either ggplot() or specific layer. Aesthetics supplied # to ggplot() are used as defaults for every layer. ggplot(mpg, aes(displ, hwy)) + geom_point() ggplot(mpg) + geom_point(aes(displ, hwy)) # Tidy evaluation ---------------------------------------------------- # aes() automatically quotes all its arguments, so you need to use tidy # evaluation to create wrappers around ggplot2 pipelines. The # simplest case occurs when your wrapper takes dots: scatter_by <- function(data, ...) { ggplot(data) + geom_point(aes(...)) } scatter_by(mtcars, disp, drat) # If your wrapper has a more specific interface with named arguments, # you need "enquote and unquote": scatter_by <- function(data, x, y) { x <- enquo(x) y <- enquo(y) ggplot(data) + geom_point(aes(!!x, !!y)) } scatter_by(mtcars, disp, drat) # Note that users of your wrapper can use their own functions in the # quoted expressions and all will resolve as it should! cut3 <- function(x) cut_number(x, 3) scatter_by(mtcars, cut3(disp), drat) </pre> <hr /><div style="text-align: center;">[Package <em>ggplot2</em> version 3.3.2 <a href="00Index.html">Index</a>]</div> </body></html>