I cannot figure out how to label each vline with year. can someone help? Below is an example of my dataset and code. I would like to label the year on the mean length vline and/or have the same colour code as the year in the figure legend.
Sector2 Family Year Length
BUN Acroporidae 2010 332.1300496
BUN Poritidae 2011 141.1467966
BUN Acroporidae 2012 127.479
BUN Acroporidae 2013 142.5940556
MUR Faviidae 2010 304.0405
MUR Faviidae 2011 423.152
MUR Pocilloporidae 2012 576.0295
MUR Poritidae 2013 123.8936667
NTH Faviidae 2010 60.494
NTH Faviidae 2011 27.427
NTH Pocilloporidae 2012 270.475
NTH Poritidae 2013 363.4635
require('ggplot2')
require('plyr')
ggplot(NMPSCFAM, aes(Length, fill=Year)) +
geom_histogram(position="dodge", binwidth=50, colour="black") + xlim(0, 500) +
scale_fill_grey(start = 1, end = 0)+
geom_vline(data=ddply(NMPSCFAM, Year~Family~Sector2, numcolwise(mean)),
mapping=aes(xintercept=Length), linetype=2) +
xlab("Length Class") +
ylab(expression(paste("Total Count"))) + #( ", m^2, ")", sep =
facet_wrap( ~ Family + Sector2, ncol=3, scales = "free")