[R] ggplot2: further query about back to back bar plots
g.rudge at bham.ac.uk
Thu Jul 25 19:30:32 CEST 2013
Further to my recent post on this topic and thanks to help received already (thanks BTW), I've got back-to-back plots working nicely to give me population pyramids, with some overlaid point data from a different time period, using the code below.
#melt the data set
#here is the plot
Two questions remaining. Firstly have I used a large amount of code to acheive this or is this about right for the effect that I'm after?
Secondly I'm quite confused about how to put a legend onto a plot like this. I'm getting slowly into the ggplot way of doing things, but I'm totally baffled by legends; say I wanted a legend with an appropriate label for both genders and both time periods showing the colours of the bars and dots I've used here as examples, how do I do this? I've tried scale_fill with a bunch of arguments to no avial. I'm confused about where in the hierarchy of ggplot commands you actually build the legend and how you map it to your data. The usual trawl of the package pdf / cook book for R etc hasn't really helped. Can someone show me how to do this please?
More information about the R-help