mean_2sd: A Function to set the hinges of boxplt equal to 1.96 Std. Dev

View source: R/boxplot_redef_function.R

mean_2sdR Documentation

A Function to set the hinges of boxplt equal to 1.96 Std. Dev

Description

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

Usage

mean_2sd(x)

Arguments

x

a vector of numeric data

Examples

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


JenC36/JACtools documentation built on Oct. 20, 2024, 8:05 a.m.