如何对ggplot堆积条进行排序?

时间:2019-05-12 13:26:00

标签: r ggplot2

我正试图创建堆叠的条形图,我想对它进行排序,以使最大的堆叠位于图的底部,其中一个嵌套在其顶部,依此类推。

这是我的代码:

g <- ggplot(df, aes(x = Year, y = Value))
g + geom_bar(aes(fill=Type), width = 0.5, stat="identity") + 
  theme(axis.text.x = element_text(angle=65, vjust=0.6),
        axis.text.y = element_blank()) +
  scale_fill_brewer(palette="Set3") +
  labs(title="GEO Types", 
       subtitle="")

这是我的数据框:

       Year                       Type Value
tmp    2010   Genome binding/occupancy   664
tmp.1  2010 Genome variation profiling   313
tmp.2  2010     Methylation profailing     0
tmp.3  2010   Non-coding RNA profiling   344
tmp.4  2010                      Other    71
tmp.5  2010          Protein profiling     8
tmp.6  2010             SNP genotyping    75
tmp.7  2010     Third-party reanalysis    15
tmp.8  2010       Expression profiling  4615
tmp.9  2011   Genome binding/occupancy   929
tmp.10 2011 Genome variation profiling   334
tmp.11 2011     Methylation profailing     0
tmp.12 2011   Non-coding RNA profiling   463
tmp.13 2011                      Other   123
tmp.14 2011          Protein profiling    21
tmp.15 2011             SNP genotyping    79
tmp.16 2011     Third-party reanalysis    18
tmp.17 2011       Expression profiling  5629
tmp.18 2012   Genome binding/occupancy   792
tmp.19 2012 Genome variation profiling   345
tmp.20 2012     Methylation profailing     0
tmp.21 2012   Non-coding RNA profiling   548
tmp.22 2012                      Other   175
tmp.23 2012          Protein profiling    21
tmp.24 2012             SNP genotyping    65
tmp.25 2012     Third-party reanalysis    23
tmp.26 2012       Expression profiling  6297
tmp.27 2013   Genome binding/occupancy  1527
tmp.28 2013 Genome variation profiling   270
tmp.29 2013     Methylation profailing     0
tmp.30 2013   Non-coding RNA profiling   688
tmp.31 2013                      Other   332
tmp.32 2013          Protein profiling    39
tmp.33 2013             SNP genotyping    85
tmp.34 2013     Third-party reanalysis    23
tmp.35 2013       Expression profiling  7037

这是我得到的情节:

plot

我希望“表达图”位于情节的底部。

0 个答案:

没有答案
相关问题