0

I want to plot several bar plots next to each other.
My subplots are labelled according to the column "meter". I would like to have them in the order of increasing meter. Unfortunately if I have a sample of 350-400 meter, the ones starting with 1 ( eg. 1400-1450) are plotted first. The addition of -1, -2 to some of the meter-labels does not seem to influence the order but might be a problem in solving the first problem.
Hope this is clear, thanks for your help.

this is my code

qplot(group, geom="bar", data=KANAL, weight=count, facets=.~meter, xlab="Korngrösse in [cm]",ylab="Anzahl", main="Korngrössenverteilung des Substrats in der kanalisierte Strecke") +
theme(axis.text.x = element_text(angle = 90, v = 1), text =element_text(size = 20)) +
scale_x_discrete(breaks=c("a", "b", "c", "d", "e"), labels=c("1-4 cm","4-7 cm","7-10 cm", "10-20 cm", "20-30 cm")) +
scale_y_continuous(limits=c(0, 250))

This is a sample of my data:

Strecke group   count   meter
N       a       86      0-50
N       b       38      0-50
N       c       17      0-50
N       d       12      0-50
N       e        0      0-50
N       a      165      350-400 
N       b        4      350-400
N       c        2      350-400
N       d        2      350-400
N       e        0      350-400
N       a      167      1250-1300 
N       b       23      1250-1300 
N       c        4      1250-1300 
N       d        0      1250-1300 
N       e        0      1250-1300 
N       a       67      1400-1450-1
N       b       55      1400-1450-1
N       c       20      1400-1450-1
N       d       18      1400-1450-1
N       e        9      1400-1450-1  
N       a      207      1400-1450-2
N       b       10      1400-1450-2 
N       c        0      1400-1450-2
N       d        0      1400-1450-2
N       e        0      1400-1450-2
N       a       77      1450-1500
N       b       76      1450-1500
N       c       14      1450-1500
N       d        5      1450-1500
N       e        0      1450-1500
Cath
  • 23,906
  • 5
  • 52
  • 86
Katharina
  • 17
  • 4

1 Answers1

2

You just need to format your meter column as a factor with levels ordered :

KANAL$meter<-factor(KANAL$meter,levels=c("0-50","350-400","1250-1300","1400-1450-1","1400-1450-2","1450-1500"),ordered=T)

Then just pass your qplot code and the categories will be correctly ordered:

enter image description here

Cath
  • 23,906
  • 5
  • 52
  • 86