r - Changing whisker definition in geom_boxplot -
i'm trying use ggplot2 / geom_boxplot produce boxplot whiskers defined 5 , 95th percentile instead of 0.25 - 1.5 iqr / 0.75 + iqr , outliers new whiskers plotted usual. can see geom_boxplot aesthetics include ymax / ymin, it's not clear me how put values in here. seems like:
stat_quantile(quantiles = c(0.05, 0.25, 0.5, 0.75, 0.95))
should able help, don't know how relate results of stat set appropriate geom_boxplot() aesthetics:
geom_boxplot(aes(ymin, lower, middle, upper, ymax))
i've seen other posts people mention building boxplot-like object manually, i'd rather keep whole boxplot gestalt intact, revising meaning of 2 of variables being drawn.
geom_boxplot stat_summary can it:
# define summary function f <- function(x) { r <- quantile(x, probs = c(0.05, 0.25, 0.5, 0.75, 0.95)) names(r) <- c("ymin", "lower", "middle", "upper", "ymax") r } # sample data d <- data.frame(x=gl(2,50), y=rnorm(100)) # ggplot(d, aes(x, y)) + stat_summary(fun.data = f, geom="boxplot") # example outliers # define outlier want o <- function(x) { subset(x, x < quantile(x)[2] | quantile(x)[4] < x) } # ggplot(d, aes(x, y)) + stat_summary(fun.data=f, geom="boxplot") + stat_summary(fun.y = o, geom="point")
Comments
Post a Comment