pass character strings to ggplot2 within a function

后端 未结 1 1976
南旧
南旧 2020-11-27 18:20

Often I use ggplot2 in my work and build wrapper functions to speed up my work flow. The use of the non-standard evaluation (NSE) aes forces me to use the actual variable n

相关标签:
1条回答
  • 2020-11-27 19:06

    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")
    
    0 讨论(0)
提交回复
热议问题