各 vline に年をラベル付けする方法がわかりません。誰かが助けることができますか?以下は、私のデータセットとコードの例です。平均長 vline に年をラベル付けしたい、および/または図の凡例の年と同じカラー コードを使用したいと考えています。
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")