【发布时间】:2016-04-22 07:53:42
【问题描述】:
这可能看起来像this question 的重复,但实际上我想扩展原始问题。
我想用 ggplot 中每组和子组的观察次数来注释箱线图。按照示例或原始帖子,这是我的最小示例:
require(ggplot2)
give.n <- function(x){
return(c(y = median(x)*1.05, label = length(x)))
# experiment with the multiplier to find the perfect position
}
ggplot(mtcars, aes(factor(cyl), mpg, fill = factor(gear))) +
geom_boxplot() +
stat_summary(fun.data = give.n, geom = "text", fun.y = median)
【问题讨论】:
-
如果我理解正确,我认为你需要 facet_wrap。