I want to label the output of my function call (which is the sum of length per month) on top of each bar.
I have tried to store the desired numbers in a vector and use this as a label but this did not work.
Here is my example code
library(ggplot2)
month<-c(1,3,2,4,3,10,12,4,9,5,6,6,7,9,9,8,10,9,11,12,9)
length<-c(2,3.5,4,10,14,16,20,34,10.5,2,10.4,3.4,4,5,6,12,5,34,5.6,56.5,22)
year<-c(2019,2018,2018,2017,2018,2016,2016,2017,2018,2019,2016,2017,2017,2018,2019,2016,2017,2018,2019,2016,2019)
df<-data.frame(month,length,year)
ggplot(df) +
geom_bar(aes(month, length, fill = as.factor(year)),
position = "stack", stat = "summary", fun.y = "sum")+
scale_x_continuous(breaks = seq(1,12,by = 1))
Is there any way to use the output of fun.y = "sum"
directly as the geom_text()
label?