Box Plot with standard deviation

Asked

Viewed 888 times

0

I need to make a standard deviation boxplot chart, but I don’t know how it does it in R.

I want to do for biomass capture and number of individuals in separate graphs, if you can give me an example.

  • I think this question and the answer may help you: https://answall.com/q/254924/64969 my ignorance in [tag:r] does not allow me to go much further than this present comment

  • 2

    I don’t understand what you mean by a boxplot graph with standard deviation. Boxplots have another way of showing data variability, using interquartile distance, not standard deviation. And, by the way, you can post the exit from dput(dados) on the question? If it is too big, dput(head(dados, 20)).

  • 1

    Technically, it is possible to build a boxplot with standard deviation. I find it odd and can cause the reader to get confused if this is not explicit. As Rui said, the boxplots are built with the quartiles, which are a measure of position. I do not understand what it would mean to put a measure of dispersion as the standard deviation in the boxplot. It would limit the box within the range (Média - DesvioPadrão; Média - DesvioPadrão), in an analogy to the interval (Q_1; Q_3) of the traditional boxplot? Anyway, it is a question that needs further clarification.

  • 1

    If you really want to represent standard deviation and mean (imagine), consider a graph with error bar instead of boxplot.

1 answer

1

Here’s how you can produce box-and-moustache charts (box-and-Whiskers Plots or boxplots) with the mean as a measure of central trend 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 of a single variable, x. The trick is to use the exit from boxplot, which is a list, and manually modify one of the members of that list, which gives the chart 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 is easy to generalize.)
The method is exactly the same, only the calculations of means and standard deviations change.

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)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.