Box plot with standard deviation

0

I need to make a boxplot chart with standard deviation, but I do not know how to do it in R.

I want to make biomass capture and number of individuals in separate charts if you can give me an example.

    
asked by anonymous 28.03.2018 / 04:03

1 answer

1

Here's how you can produce box-and-whiskers plots and boxplots) with the average as a measure of central tendency and with the standard deviation as a measure of variability.

First, generate the data.

set.seed(1412)    # Torna o código reprodutível

n <- 1e3
x <- rnorm(n)
y <- rnorm(n)

Now the boxplot is a single variable, x . The trick is to use the output of boxplot , which is a list, and manually modify one of the members of that list, which gives the graph statistics. In this case, bp$stats .

bp <- boxplot(x, plot = FALSE)

m <- mean(x, na.rm = TRUE)
s <- sd(x, na.rm = TRUE)
bp$stats[2, 1] <- m - s
bp$stats[3, 1] <- m
bp$stats[4, 1] <- m + s

bxp(bp)    # É esta função que desenha os boxplots

Now the same but with several variables. (Only two, it's easy to generalize.)
The method is exactly the same, it only changes the calculations of the means and standard deviations.

mat <- cbind(x, y)
bp2 <- boxplot(mat, plot = FALSE)

m2 <- colMeans(mat, na.rm = TRUE)
s2 <- apply(mat, 2, sd, na.rm = TRUE)
bp2$stats[2, ] <- m2 - s2
bp2$stats[3, ] <- m2
bp2$stats[4, ] <- m2 + s2

bxp(bp2)
    
21.05.2018 / 17:48