I am using the following in R to generate a Boxplot out of a given set of data:
ggplot(data = daten, aes(x=Bodentyp, y=Fracht)) + geom_boxplot(aes(fill=Bewirtschaftungsform))
Now I want to display the number of data points going into each category of the column "Bodentyp". How do I achieve this?
You can use fun.data
to apply a function ( f
) to the grouped data to return a count ( length(y)
) and a position for the label ( median(y)
)
f <- function(y)
c(label=length(y), y=median(y))
library(ggplot2)
data(mtcars)
ggplot(mtcars, aes(x=as.factor(cyl), y=mpg)) +
geom_boxplot() + theme_bw() +
stat_summary(fun.data=f, geom="text", vjust=-0.5, col="blue")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.