I am trying to create a population pyramid using the following code:
HH_rep$AGEcut <- cut(HH_rep$age,seq(0,100,5))
ggplot(data=HH_rep,aes(x= AGEcut,fill=sex)) +
geom_bar(data=subset(HH_rep,sex=="female")) +
geom_bar(data=subset(HH_rep,sex=="male"),aes(y=..count..*(-1))) +
scale_y_continuous(breaks=seq(-1000,1000,200),labels=abs(seq(-1000,1000,200))) +
coord_flip()
I get a pyramid plot ( see image)
However each time the age-group 5-10yrs jumps into the middle of the graph instead of being in sequential order. Even after releveling the the same problem occurs. Any idea how I can overcome this issue?