I'm trying to create a labeled stacked bar chart where there is only ever 1 bar. My stacks are not always large enough to fit text so I would like to have leader lines that point to the label just to the right of the stack for the labels that can't fit in the stack. Alternatively, it is okay if all the labels are all to the right of the stack with leader lines.
My data.frame looks something like this:
Regional.District Municipality Population.2010 mp
Metro Bowen Island 3678 1839.0
Metro Coquitlam 126594 66975.0
Metro Delta 100000 180272.0
Metro Langley City 25858 243201.0
Metro Maple Ridge 76418 294339.0
Metro New West 66892 365994.0
Metro North Vancouver (City) 50725 424802.5
Metro Port Coquitlam 57431 478880.5
Metro Port Moody 33933 524562.5
Metro Surrey 462345 772701.5
Metro West Vancouver 44058 1025903.0
Metro White Rock 19278 1057571.0
Metro Anmore 2203 1068311.5
Metro Belcarra 690 1069758.0
Metro Burnaby 227389 1183797.5
Metro Langley (Town) 104697 1349840.5
Metro Lions Bay 1395 1402886.5
Metro Metro Vancouver-uninc 24837 1416002.5
Metro North Vancouver (District) 88370 1472606.0
Metro Pitt Meadows 18136 1525859.0
Metro Richmond 196858 1633356.0
Metro Vancouver (City) 642843 2053206.5
This is what I currently have working:
This is what I'd like to get working:
Here is my code:
library(ggplot2)
ggplot(muns, aes(x = Regional.District, y = Population.2010, fill = Municipality)) +
geom_bar(stat = 'identity', colour = 'gray32', width = 0.6, show_guide = FALSE) +
geom_text(aes(y = muns$mp, label = muns$Municipality), colour = 'gray32')
Is this possible to automate? I am okay with not using ggplot2 to accomplish this. Thanks!