Любая идея, как передать переменную сортировки строк в 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.
Есть предложения?