Good morning, my name is Thiago and I'm having a hard time building a legend on ggplot2. The data are of wood density vs planting age and the graph I'm trying to build is with the following code:
d.idade<-ggplot(data=dens, aes(x=Idade, y=Densidade))+
geom_point(pch=1, size=1.4)+
geom_hline(yintercept = mean(dens$Densidade), linetype=2, color="red4", show.legend = TRUE)+
xlim(c(0,25))+
ylim(c(250,700))+
xlab("Age (years)")+
ylab("Wood density (kg/m³)")+
theme_classic()+
theme(axis.text.x = element_text(colour = "black", family="serif", size=10))+
theme(axis.text.y = element_text(colour = "black", family="serif", size=10))+
theme(axis.title.x = element_text(family ="serif", size=10))+
theme(axis.title.y = element_text(family="serif", size=10))
I used the geom_hline command to construct a line representing the mean of the wood density values.
However, I would like to construct a legend that indicates that this line represents the average with the line style used and that appears in bottom of the graph.
I have tried several geom_label commands and legend, but I did not succeed in any of them, since I want the symbol (color, line type) and the description (mean valeus) of the line appear on the legend.