View source: R/boxplot_redef_function.R
mean_2sd | R Documentation |
This function re-defines the hinges of a boxplot to equal the mean +/- 1.96 standard deviation of the data
and the whiskers to be the range of the data (min and max).
If datapoints are normally distributed, this would equate to +/- 95% Confidence Interval
See also mean.sd for box defined by 1 std. dev
mean_2sd(x)
x |
a vector of numeric data |
a <- rnorm(50, 0, 1)
b <- rnorm(120, 0.5, 1.5)
c <- rnorm(70, 1, 0.5)
d <- rnorm(15, 0,1)
group <- factor(rep(1:4, c(50, 120, 70, 15)))
mydata <- data.frame(c(a,b,c,d), group)
names(mydata) <- c("value", "group")
p2 <- ggplot(aes(y = value, x = factor(group)), data = mydata)
p2 <- (p1 + stat_summary(fun.data = mean.2sd, geom = "boxplot")
+ geom_jitter(position=position_jitter(width=.2), size=1.5)
+ ggtitle("Boxplot con media, 2Std. Dev. (95%CI), valore min. e max.") + xlab("Gruppi") + ylab("Valori"))
p2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.