2

I am plotting a bar-graph with multiple variables, but the values on the y-axis are not getting sorted from low to high. Do I need to specify that?

 head(data.m)

       miRNA variable         value
 1 hsa-miR-92a-3p     Ago1 16.1916036788
 2 hsa-miR-99b-5p     Ago1 15.6601825183
 3  hsa-let-7e-5p     Ago1 13.4926162349
 4 hsa-miR-15b-5p     Ago1 11.3220579493
 5   hsa-miR-378i     Ago1  6.0752193103
 6 hsa-miR-222-3p     Ago1  6.6619305684
 ggplot(data.m, aes(variable, value, fill=variable)) + geom_bar(stat="identity") + facet_grid(~miRNA, scales="free_y")
user3741035
  • 2,455
  • 4
  • 15
  • 20
  • 1
    possible duplicate of [Order Bars in ggplot2 bar graph](http://stackoverflow.com/questions/5208679/order-bars-in-ggplot2-bar-graph) – hrbrmstr Sep 24 '14 at 10:53

1 Answers1

1

Try:

data.m$miRNA = factor(as.character(data.m$miRNA), levels = data.m$miRNA[order(data.m$value)])
ggplot(data.m, aes(miRNA, value, fill=variable)) + geom_bar(stat="identity")

enter image description here

rnso
  • 23,686
  • 25
  • 112
  • 234