aes_string
Generate aesthetic mappings from a string
Aesthetic mappings describe how variables in the data are mapped to visual properties (aesthetics) of geoms. Compared to aes this function operates on strings rather than expressions.
Usage
aes_string(...)
Arguments
- ...
- List of name value pairs
Details
aes_string
is particularly useful when writing
functions that create plots because you can use strings
to define the aesthetic mappings, rather than having to
mess around with expressions.
See Also
Examples
aes_string(x = "mpg", y = "wt")
aes(x = mpg, y = wt)
Community examples
``` # 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") ```