Sort legend in ggplot2

后端 未结 2 1959
栀梦
栀梦 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 14:58

    you can use a new option reverse = TRUE:

    ggplot(datam,aes(x = variable, y = value,fill = factor(as.numeric(ind)))) +
      geom_bar(position = "fill") + scale_y_continuous(labels =percent_format()) +
      scale_fill_discrete("Barcode\nMatch") + xlab("Barcode")+ylab("Reads") +
      guides(fill = guide_legend(reverse = TRUE))
    

    enter image description here

提交回复
热议问题