Reverse order of discrete y axis in ggplot2

前端 未结 6 712
情歌与酒
情歌与酒 2020-12-01 06:10

Situation & data

I have a dataframe df of athlete positions in a race (I\'ve already melted it for use with ggpl

6条回答
  •  醉话见心
    2020-12-01 06:32

    Another option using the forcats package.

    ggplot(df, aes(x = distanceRemaining, y = forcats::fct_rev(factor(position))))
    

    This has the advantage of keeping everything in the ggplot call, and playing nicely with other options such as coord_flip and facets_wrap(..., scales = "free")

提交回复
热议问题