ggplot中的订单栏 [英] Order bars in ggplot
本文介绍了ggplot中的订单栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在ggplot中绘制一个barplot:
I am plotting a barplot in ggplot:
ggplot(fastqc.dat,aes(y=fastqc.dat$ReadCount,x=fastqc.dat$Sample)) + geom_bar(stat="identity",position="identity",fill="darkblue") + xlab("Samples") + ylab("Read Counts") + opts(axis.text.x=theme_text(angle=-90))
我的文件'fastqc.dat'看起来像这样:
My file 'fastqc.dat' looks like this:
Sample ReadCount
201304950-01_ATTCAGAA_R1 27584682
201304951-01_GAATTCGT_R1 25792086
201304952-01_CTGAAGCT_R1 36000000
201304953-01_GAGATTCC_R1 35634177
201304954-01_ATTACTCG_R1 88906701
它产生以下图:
但是我想根据读取计数即Y轴重新排列条形.我尝试了很多事情,但不会发生.我什至尝试根据ReadCount列对fastqc.dat进行排序.有什么建议吗?
But I want to reorder the bars based on the read counts i.e. the Y axis. I tried a lot of things but it just won't happen. I even tried sorting fastqc.dat based on ReadCount column. Any suggestions?
推荐答案
...因此,将有用的建议汇总在一起,一种解决方案是:
... so bringing the helpful suggestions together, one solution would be:
fastqc.dat$Sample <- factor(fastqc.dat$Sample,
levels=fastqc.dat$Sample[order(fastqc.dat$ReadCount)])
然后使用您的代码...
and than use your code...
HTH
这篇关于ggplot中的订单栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文