在geom_bar ggplot2中重新排列条形图 [英] Reorder bars in geom_bar ggplot2
本文介绍了在geom_bar ggplot2中重新排列条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在试图制作一个条形图,其中的图是从 miRNA
以最高的值
排序的。到最低的 miRNA
。为什么我的代码无效?
I am trying to make a bar-plot where the plot is ordered from the miRNA
with the highest value
to the miRNA
with the lowest. Why does my code not work?
> head(corr.m)
miRNA variable value
1 mmu-miR-532-3p pos 7
2 mmu-miR-1983 pos 75
3 mmu-miR-301a-3p pos 70
4 mmu-miR-96-5p pos 5
5 mmu-miR-139-5p pos 10
6 mmu-miR-5097 pos 47
ggplot(corr.m, aes(x=reorder(miRNA, value), y=value, fill=variable)) +
geom_bar(stat="identity")
推荐答案
您的代码工作正常,但barplot从低到高排序。如果您想将酒吧从高到低排序,您必须在值
之前添加 -
标记:
Your code works fine, except that the barplot is ordered from low to high. When you want to order the bars from high to low, you will have to add a -
sign before value
:
ggplot(corr.m, aes(x = reorder(miRNA, -value), y = value, fill = variable)) +
geom_bar(stat = "identity")
给出:
这篇关于在geom_bar ggplot2中重新排列条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文