使用 dplyr 的管道后无法识别的变量

Unrecognized variable after a pipe with dplyr

我正在使用 gapminder 数据集与 plotly 库一起制作交互式条形图。我想使用 forcats 库对 continent 变量中的级别重新排序,但是当我将它放在管道之后时它无法识别该变量。这是我正在使用的脚本:

gapminder %>%
        filter(year==2002) %>%
        mutate(continent=fct_reorder(continent, pop, .desc=T))

我想知道为什么变量“continent”不通过管道。谢谢

尝试此操作以节省您在 gapminder 上的管道操作:

gapminder %>%
        filter(year==2002) %>%
        mutate(continent=fct_reorder(continent, pop, .desc=T)) -> gapminder