Legend ordering in ggplot2

前端 未结 2 1534
别跟我提以往
别跟我提以往 2020-12-18 14:16

I created the following graph in R using ggplot2. As you can see, the order in the legend is not exactly what it should be: I would like to have \"

2条回答
  •  有刺的猬
    2020-12-18 14:25

    It's changing names into a factor variable and using alphabetical order by default

    use

    df$names <- factor(df$names, levels = c("1 year","4 years","15 years","25 years","40 years"))
    

提交回复
热议问题