Creating box plot for multiple inputs with range, mean and standard deviation value

I have eleven (11) different farm inputs with a calculated range. Apart from these, mean and standard deviation (SD) is also computed.
I want to draw box plot for each input.
e.g, Input 1
X : 5.8-7.8 (Range), mean: 6.13 and SD = 0.75.

How to bring all these stuff in boxplot ?

Thank you.

Hi Paresh,

a box-and-whiskers plot have a well defined five-number summary of your data so in general one should not change the meaning of the box and the whiskers. So by definition a boxplot shows the median not the mean!

In general, you can plot a boxplot in ggplot2 like this:


ggplot(mpg, aes(class, displ)) +

Created on 2020-08-20 by the reprex package (v0.3.0)
(since you did not provide any data or code using an in-build dataset)

What you can do to highlight also the average and the standard deviation is adding that on top of your boxplots. In the first example I use stat_summary that by default calculates the mean and standard error and might be a better choice than standard deviation, but decide yourself - no need to precalculate the stats here). Or you can define the summary stats yourself (2nd example):


ggplot(mpg, aes(class, displ)) +
  geom_boxplot() +
  stat_summary(color = "red")
#> No summary function supplied, defaulting to `mean_se()`

ggplot(mpg, aes(class, displ)) +
  geom_boxplot() +
  stat_summary(fun = mean, color = "red") +
    fun.min = function(x) mean(x) - sd(x), 
    fun.max = function(x) mean(x) + sd(x), 
    geom = "errorbar",
    color = "red",
    width = .3
#> Warning: Removed 7 rows containing missing values (geom_segment).

Created on 2020-08-20 by the reprex package (v0.3.0)

1 Like

Hi Z3tt,
Please find the screenshot for the data you are asking.

Hi Paresh, thanks for sharing your data but this doesn't help us. How should I get this in my R script? Please have a look here how to provide a proper reproducible example.

I also think my answer already was the solution to the issue. Import your data and refer to the dataframe and variables as in the example.