R ggplot中的顺序条

R ggplot中的顺序条,r,ggplot2,R,Ggplot2,我正在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”如下所

我正在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”如下所示:

             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进行排序。有什么建议吗?

我让它起作用了。我必须将aes(x=fastqc.dat$Sample)添加到geom_bar()中,如下所示:

fastqc.dat$Sample <-factor(fastqc.dat$Sample, levels=fastqc.dat[order(fastqc.dat$ReadCount), "Sample"])

ggplot(fastqc.dat,aes(x=fastqc.dat$Sample,y=fastqc.dat$ReadCount)) + geom_bar(aes(x=fastqc.dat$Sample),stat="identity",position="identity",fill="darkblue") + xlab("Samples") + ylab("Read Counts") + opts(axis.text.x=theme_text(angle=-90))

fastqc.dat$Sample。。。因此,将这些有用的建议结合在一起,一个解决方案是:

fastqc.dat$Sample <- factor(fastqc.dat$Sample,
                            levels=fastqc.dat$Sample[order(fastqc.dat$ReadCount)])

fastqc.dat$示例我看到了那个问题,然后发布了我的问题。答案对我没有帮助。看看这篇最近的博文:如果你仍然无法获得它,请发布一个数据集,我们可以一起玩,并发布你尝试过但不起作用的代码。这不是一个好的解决方案。您(基本上)不应该在
aes()
中使用
$
。答案是重新排列因子的等级,就像在副本中一样。谢谢,我忘了加那一行。