Hi, I have been trying to code for a histogram with groups that include the mean value for each group on the plot using geom_point() but keep getting the error "stat_summary requires the following missing aesthetics: y". I would greatly appreciate some help in understanding what is happening here. Thanks in advance.
code used:
fin2.2 <- finch%>%select(Species,WingL,BodyL)
sppf<-factor(finch[,1])
ggplot(fin2.2, aes(x=WingL,fill=Species, color=Species)) +
geom_histogram(position="identity",bins=20, alpha=0.5)+
scale_fill_manual(values=c("red","grey","green","purple","cyan"))+
labs(title= "Histogram of wing lengths in finches",x="Wing lengths (mm)", y = "Frequency")+
geom_point() +
stat_summary(geom = "point", fun = "mean", colour = "sppf", size = 2.0)
Do you mean to do something like this? I used the result of stat_summary to mark the mean WingL for each Species. I put the y value in manually. I see the colors are not quite right, so that needs to be fixed.
Thank you so much for your help. Including the mapping parameter in the code fixed the problem and the plot looks great now. I am still new to coding in R and I wondered why the hashtag in front of #geom_point() improved the code? It was my understanding that # allows R to ignore those sections?
I put the # in front of geo_point to remove it from the code. I did that rather than simply deleting that line so it would be obvious that my solution did not include the geom_point. The stat_summary includes the argument geom = "point" and that is what causes the points to appear on the plot.