首页 文章

ggplot中的订单栏[重复]

提问于
浏览
0

这个问题在这里已有答案:

我在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

它产生以下图:
enter image description here

但我想根据读数(即Y轴)对条形图进行重新排序 . 我尝试了很多东西,但它不会发生 . 我甚至尝试基于ReadCount列对fastqc.dat进行排序 . 有什么建议?

2 回答

  • -3

    ...所以将有用的建议结合在一起,一个解决方案是:

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

    而不是使用你的代码......

    HTH

  • 1

    我得到了它的工作 . 我必须将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))
    

    这将条形排列在X轴上 .

相关问题