Sort legend in ggplot2

后端 未结 2 1967
栀梦
栀梦 2020-12-01 14:05

I have produced a stacked percent barplot from the following data, which is in a csv file,

,ONE,TWO,THREE
1,2432,420,18
2,276,405,56
3,119,189,110
4,90,163,1         


        
2条回答
  •  余生分开走
    2020-12-01 15:06

    Add + scale_fill_hue(breaks=c("new order 1","new order 2","new order...")) as in:

    library(ggplot2)
    ggplot(data=PlantGrowth, aes(x=group, fill=group)) + geom_bar() + 
        geom_bar(colour="black", legend=FALSE) + 
        scale_fill_hue(breaks=c("trt1","ctrl","trt2"))
    

    I'd also check out http://wiki.stdout.org/rcookbook/Graphs/Legends%20(ggplot2)/ for more.

    This may have changed and become easier with he new ggplot but I'm not sure.

提交回复
热议问题