pass character strings to ggplot2 within a function

There’s the aes_string function, that I don’t really see given prominence, which does exactly this:

FUN <- function(dat, x, y) {
    ggplot(dat, aes_string(x = x, y = y)) +
        geom_point()
}

FUN(mtcars, "mpg", "hp")

Leave a Comment