If I use ggplot2
's stat_summary()
to make a barplot of the average number of miles per gallon for 3-, 4-, and 5-geared cars, for example, how can I label each of the bars 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 normally use geom_text()
, but I'm having trouble figuring out what to do in order to get the average value from stat_summary()
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…