知道如何将字符串排序变量传递给fct_reorder
吗?
require(dplyr)
require(forcats)
require(ggplot2)
order_var = 'displ'
mpg %>% mutate(manufacturer = fct_reorder(manufacturer, order_var))
#> Error in mutate_impl(.data, dots): Evaluation error: length(f) == length(.x) is not TRUE.
试过bang bang !!
:
mpg %>% mutate(manufacturer = fct_reorder(manufacturer, !!order_var))
#> Error in mutate_impl(.data, dots): Evaluation error: length(f) == length(.x) is not TRUE.
试过eval
:
as.name(eval(order_var))
#> displ
mpg %>% mutate(manufacturer = fct_reorder(manufacturer, as.name(eval(order_var))))
#> Error in mutate_impl(.data, dots): Evaluation error: length(f) == length(.x) is not TRUE.
有什么建议么?