0

I have a data, 64 rows, 3 columns as below. I want to fill each bar based on the colors.

#Code     Route1   colors
# 0        0.25       a
# 1        0.08       b
# 10       0.02       b
# 11       0.11       b
# 100      0.04       b
# 101      0.04       b
# 110      0.06       b
# 111      0.03       b
# 1000     0.02       c
# ...       ...      ...

#Character  Numerical  Factor


ggplot(mydata, aes(x = Code, y=Route1, fill=colors)) +
  geom_bar(stat="identity", width=0.7)

enter image description here

The order of bars does not follow the column Code.

Soheil
  • 954
  • 7
  • 20
  • 1
    Suggested dupe: [Order bars in ggplot2](http://stackoverflow.com/q/5208679/903061). `ggplot` doesn't care about the row order of your data frame. If you make `code` a `factor` with the levels in the order you want, it will follow that order. `mydata$code = factor(mydata$code, levels = mydata$code)` should work. – Gregor Thomas May 18 '16 at 23:27
  • Very helpful, it worked. – Soheil May 18 '16 at 23:30

0 Answers0