此问题询问有关根据未汇总表排序条形图的问题。我的情况略有不同。这是我原始数据的一部分:
experiment,pvs_id,src,hrc,mqs,mcs,dmqs,imcs
dna-wm,0,7,9,4.454545454545454,1.4545454545454546,1.4545454545454541,4.3939393939393945
dna-wm,1,7,4,2.909090909090909,1.8181818181818181,0.09090909090909083,3.9090909090909087
dna-wm,2,7,1,4.818181818181818,1.4545454545454546,1.8181818181818183,4.3939393939393945
dna-wm,3,7,8,3.4545454545454546,1.5454545454545454,0.4545454545454546,4.272727272727273
dna-wm,4,7,10,3.8181818181818183,1.9090909090909092,0.8181818181818183,3.7878787878787876
dna-wm,5,7,7,3.909090909090909,1.9090909090909092,0.9090909090909092,3.7878787878787876
dna-wm,6,7,0,4.909090909090909,1.3636363636363635,1.9090909090909092,4.515151515151516
dna-wm,7,7,3,3.909090909090909,1.7272727272727273,0.9090909090909092,4.030303030303029
dna-wm,8,7,11,3.6363636363636362,1.5454545454545454,0.6363636363636362,4.272727272727273
我只需要其中的几个变量,即mqs
and imcs
,按它们分组pvs_id
,所以我创建了一个新表:
m = melt(t, id.var="pvs_id", measure.var=c("mqs","imcs"))
我可以将其绘制为条形图,从中可以看到MQS和IMCS之间的相关性。
ggplot(m, aes(x=pvs_id, y=value))
+ geom_bar(aes(fill=variable), position="dodge", stat="identity")
但是,我希望生成的条按MQS值从左到右按降序排列。当然,IMCS值应该与这些值一起排序。
我怎样才能做到这一点?一般来说,给定任何熔融数据框——这似乎对 ggplot2 中的绘图很有用,而且今天是我第一次偶然发现它——我如何指定一个变量的顺序?