r - modify stat_summary to show only a few point -
currently have boxplot below , stat_summary used show quantiles of each distribution text.
group = c( rep(c(1,2),100) ) r = rnorm(200,50,63) d = data.frame( group = group, r = r ) head(d) ggplot(data = d, aes(factor(group), r)) + geom_boxplot() + stat_summary(geom="text", fun.y= quantile, aes(label=sprintf("%1.0f", ..y..)), position=position_nudge(x=0.33), size=3)
you can see quantiles printed text via fun.y= quantile
line of code. how can modify code print median , min , max printing 3 points instead of 5?
i can create function , select quantiles want
ff= function (x) { return(quantile(x)[1]) }
and use fun.y= quantile
, print want how incorporate fun.y directly in stat_summary call?
thank you.
add fun.args
stat_summary
follows:
ggplot(data = d, aes(factor(group), r)) + geom_boxplot() + stat_summary(geom="text", fun.y=quantile, fun.args=list(probs=c(0,.5,1)), aes(label=sprintf("%1.0f", ..y..)), position=position_nudge(x=0.33), size=3)
Comments
Post a Comment