Create Boxplot with Previously Calculated Statisitics in R (2 Examples)

In this article, I’ll explain how to create a boxplot with previously calculated statisitics in R programming.

Example 1: Drawing a Boxplot from Pre-Calculated Values Using Base R

base_list <- list(stats = matrix(11:15, ncol = 1),  # Create list with stats
                  n = 5)
base_list
# $stats
#      [,1]
# [1,]   11
# [2,]   12
# [3,]   13
# [4,]   14
# [5,]   15
# 
# $n
# [1] 5
bxp(base_list)                                      # Base R boxplot with precomputed values

r graph figure 1 create boxplot previously calculated statisitics r

Example 2: Drawing a Boxplot from Pre-Calculated Values Using the ggplot2 Package

install.packages("ggplot2")                         # Install & load ggplot2
library("ggplot2")
ggplot_data <- data.frame(x = "x",                  # Create data frame with stats
                          ymin = 11,
                          lower = 12,
                          middle = 13,
                          upper = 14,
                          ymax = 15)
ggplot_data
#   x ymin lower middle upper ymax
# 1 x   11    12     13    14   15
ggplot(ggplot_data,                                 # ggplot2 boxplot with precomputed values
       aes(x = x,
           ymin = ymin,
           lower = lower,
           middle = middle,
           upper = upper,
           ymax = ymax)) +
  geom_boxplot(stat = "identity")

r graph figure 2 create boxplot previously calculated statisitics r

Related Articles & Further Resources

Below, you can find some additional resources on topics such as coding errors, ggplot2, and distributions:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top