mean_sd: A function to set the hinges of boxplt equal to 1 Std. Dev

View source: R/boxplot_redef_function.R

mean_sdR Documentation

A function to set the hinges of boxplt equal to 1 Std. Dev

Description

This function re-defines the hinges of a boxplot to equal the mean +/- one standard deviation of the data and the whiskers to be the range of the data (min and max).
See also mean.2sd for box defined by 1.96 std. dev.

Usage

mean_sd(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")

p1 <- ggplot(aes(y = value, x = factor(group)), data = mydata)
p1 <- (p1 + stat_summary(fun.data = mean.sd, geom = "boxplot") 
          + geom_jitter(position=position_jitter(width=.2), size=1.5) 
          + ggtitle("Boxplot con media, 1 Std. Dev., valore min. e max.") + xlab("Gruppi") + ylab("Valori"))
p1


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