Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

aes_

Define aesthetic mappings from strings, or quoted calls and formulas.


Description

Aesthetic mappings describe how variables in the data are mapped to visual properties (aesthetics) of geoms. aes uses non-standard evaluation to capture the variable names. aes_ and aes_string require you to explicitly quote the inputs either with "" for aes_string(), or with quote or ~ for aes_(). (aes_q is an alias to aes_)

Usage

aes_(x, y, ...)

aes_string(x, y, ...)

aes_q(x, y, ...)

Arguments

x, y, ...

List of name value pairs. Elements must be either quoted calls, strings, one-sided formulas or constants.

Details

It's better to use aes_q(), because there's no easy way to create the equivalent to aes(colour = "my colour") or aes{x = `X$1`} with aes_string().

aes_string and aes_ are particularly useful when writing functions that create plots because you can use strings or quoted names/calls to define the aesthetic mappings, rather than having to use substitute to generate a call to aes().

See Also

Examples

# Three ways of generating the same aesthetics
aes(mpg, wt, col = cyl)
aes_(quote(mpg), quote(wt), col = quote(cyl))
aes_(~mpg, ~wt, col = ~cyl)
aes_string("mpg", "wt", col = "cyl")

# You can't easily mimic these calls with aes_string
aes(`$100`, colour = "smooth")
aes_(~ `$100`, colour = "smooth")
# Ok, you can, but it requires a _lot_ of quotes
aes_string("`$100`", colour = '"smooth"')

# Convert strings to names with as.name
var <- "cyl"
aes(col = x)
aes_(col = as.name(var))

animint2

Animated Interactive Grammar of Graphics

v2020.9.18
GPL-3
Authors
Toby Hocking [aut, cre] (Original animint code), Hadley Wickham [aut] (Forked ggplot2 code), Winston Chang [aut] (Forked ggplot2 code), RStudio [cph] (Forked ggplot2 code), Nicholas Lewin-Koh [aut] (hexGrob), Martin Maechler [aut] (hexGrob), Randall Prium [aut] (cut_width), Susan VanderPlas [aut] (Animint GSOC 2013), Carson Sievert [aut] (Animint GSOC 2014), Kevin Ferris [aut] (Animint GSOC 2015), Jun Cai [aut] (Animint GSOC 2015), Faizan Khan [aut] (Animint GSOC 2016-2017), Vivek Kumar [aut] (Animint GSOC 2018), Himanshu Singh [aut] (Animint2 GSoC 2020)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.