Pass variable or expression into `aes`

后端 未结 1 786
一个人的身影
一个人的身影 2021-01-20 01:49

I wrote the function to plot bar graph with factor variables. When I run my function,The error message was showed. Error in eval(expr, envir, enclos) : object \'dset\' not f

相关标签:
1条回答
  • 2021-01-20 01:54

    Converted to an answer, as it seems useful

    aes is designed to evaluate unquoted column names within the scope of the provided dataset (dset in your case). dset[, i] is not a column name, rather a whole column which aes wasn't designed to deal with.

    Fortunately, you can parse quoted column names to aes_string. Thus, using

    aes_string(x = names(dset)[i])
    

    instead of

    aes(x = dset[, i])
    

    Should solve your problem

    0 讨论(0)
提交回复
热议问题