aes_string

0th

Percentile

Generate aesthetic mappings from a string/quoted objects

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. These two variants use regular evaluation, which is easier to use inside functions.

Usage
aes_string(x = NULL, y = NULL, ...)

aes_q(x = NULL, y = NULL, ...)

Arguments
x,y,...
List of name value pairs
Details

aes_string and aes_q 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

aes

Other aesthetic generators: aes

Aliases
  • aes_q
  • aes_string
Examples
# Threee ways of generating the same aesthetics
aes(mpg, wt, col = cyl, fill = NULL)
aes_string("mpg", "wt", col = "cyl", fill = NULL)
aes_q(quote(mpg), quote(wt), col = quote(cyl), fill = NULL)

aes(col = cyl, fill = NULL)
aes_string(col = "cyl", fill = NULL)
aes_q(col = quote(cyl), fill = NULL)
Documentation reproduced from package ggplot2, version 1.0.1, License: GPL-2

Community examples

nayef.ahmad.11@gmail.com at Apr 23, 2018 ggplot2 v1.0.0

``` # define a function to create a scatterplot, allowing user to specify what to put on x- and y-axes: plot.fn.with.aes <- function(df, x.axis, y.axis, point.colour = NULL) { ggplot(df, aes_string(x = x.axis, y = y.axis, colour = point.colour)) + geom_point() } # test the function: plot.fn.with.aes(mtcars, "mpg", "cyl") plot.fn.with.aes(mtcars, "mpg", "cyl", "gear") ```