r - Add a number of observations per group AND SUBGROUP in ggplot2 boxplot -
this might seem duplicate of this question, in fact want expand original question.
i want annote boxplot number of observations per group , subgroup in ggplot. following example or original post, here minimal example:
require(ggplot2) give.n <- function(x){ return(c(y = median(x)*1.05, label = length(x))) # experiment multiplier find perfect position } ggplot(mtcars, aes(factor(cyl), mpg, fill = factor(gear))) + geom_boxplot() + stat_summary(fun.data = give.n, geom = "text", fun.y = median)
my problem number of samples line in center of group, rather plotting on appropriate boxplot (as picture below shows):
is want?
require(ggplot2) give.n <- function(x){ return(c(y = median(x)*1.05, label = length(x))) # experiment multiplier find perfect position } ggplot(mtcars, aes(factor(cyl), mpg, fill = factor(gear))) + geom_boxplot() + stat_summary(fun.data = give.n, geom = "text", fun.y = median, position=position_dodge(width=0.75))
Comments
Post a Comment