edit: clarifying per @gregor's comment, set bounds in context of stat_summary
- in case zooming out default. pre-mean data falls out side desired bounds. then, i'd set breaks, seems require use of scale_continuous
.
i've looked around while, , @ least some mailing list posts describe "problem(s) new users have" setting scales.
however, while no longer confused @ level scale_continuous
censoring out-of-bounds data, seems reduced following awkward code specify breaks if using stat_summary:
ggplot(data, aes(x=trial, linetype=primarydx, y=mtt, color=hand)) + stat_summary(fun.y = mean, geom = "line") + scale_y_continuous(limits = c(1,2), breaks = seq(1, 2, 0.2), oob=function(x, r) x) ## seems silly
here, scale_y_continuous of course censor out-of-bounds data default. supply simple identity function in place of oob=censor
.
for life of me, can find no other way specify breaks scale_([xy]_)?continuous
functions. [xy]lim
, coord_cartesian
both set limits.
is above way it? if so, maybe @ least warrants place in vignettes? (or if there better way, maybe that should go in vignettes.)
you can use coord_cartesian
zoom without omitting out-of-bounds data , still set breaks using scale_y_continuous
. adding scale_y_continuous
plot doesn't mean have set limits inside scale_y_continuous
.
demonstrating mtcars
:
p = ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_boxplot() + scale_y_continuous(breaks = c(15.2, 19.7, 26)) gridextra::grid.arrange(p, p + coord_cartesian(ylim = c(15, 28)), ncol = 2)
the above plot demonstrates this. set y breaks @ medians clear median in boxplot summary remains unchanged after zoom.
Comments
Post a Comment