If I use ggplot2 stat_summary() to make a barcode of the average number of miles per gallon for 3-, 4- and 5-speed cars, for example, how can I mark each column with the average value for mpg?
library(ggplot2) CarPlot <- ggplot() + stat_summary(data= mtcars, aes(x = factor(gear), y = mpg, fill = factor(gear) ), fun.y="mean", geom="bar" ) CarPlot
I know that you can usually use geom_text() , but it's hard for me to figure out what to do to get the average from stat_summary() .
source share