I've been working on some epidemiologic data using R and ggplot. I've plotted a population pyramid using the following code:
Data is available here, using multiplot script from here.
plot1 <- ggplot(pt.indig, aes(x=agecat, fill=gender)) +
geom_bar(position="dodge") +
scale_fill_brewer("Gender", palette="Set1") +
scale_y_continuous(breaks=c(0:10), minor_breaks=NULL) + coord_flip() +
labs(y="Indigenous Patients", x=NULL) + coord_flip() +
theme_bw() + theme(axis.text.y=element_text(hjust=-0.1))
plot2 <- ggplot(pt.nind, aes(x=agecat, fill=gender)) +
geom_bar(aes(y=..count..*(-1)), position="dodge") +
scale_fill_brewer(palette="Set1") + coord_flip() +
scale_y_continuous(breaks=seq(-11,0,1), labels=abs(seq(-11,0,1))) +
labs(x=NULL, y="Non-Indigenous Patients") +
theme(legend.position="none", axis.text.y=element_blank(), axis.ticks.y=element_blank())
multiplot(plot2, plot1, cols=2)
Produces this graph:
What I'd like to do with the graph is:
- Make the two plots the same relative size
- horizontally so the bars are proportionate
- vertically so the age categories line up properly
- Move the left graph a bit closer to the y-axis labels (or the labels across, but using hjust displaces the shorter labels (NA, and the <10 year old labels))
- Make the Non-indig 10-14 year-old male bar show as the same width as the others
- (ideally, make the NA bars the same colour, but less important than the others)
Help greatly appreciated.