我正在使用以下代码在R中绘制排序的条形图:
data %>%
mutate(channel_name = fct_reorder(channel_name, desc(column_name))) %>%
ggplot( aes(x=channel_name, y=column_name, tooltip = channel_name)) +
geom_bar_interactive(stat="identity" )
它工作正常,但现在我想动态设置绘制的列:
my_column <- "column_name"
data %>%
mutate(channel_name = fct_reorder(channel_name, desc(my_column))) %>%
ggplot( aes(x=channel_name, y=my_column, tooltip = channel_name)) +
geom_bar_interactive(stat="identity" )
但这给了我错误:
Error in fct_reorder(channel_name, desc(my_column)) :
length(f) == length(.x) is not TRUE
什么是正确的语法?