Boxplots in Base R

This section introduces the functionality of the base-R function boxplot. Note that for some data formats, the plot function with x being a factor variable will also work.

Box plot with the number of observations: gplots::boxplot2()

The function boxplot2()[in gplots package] can be used to create a box plot annotated with the number of observations.

Install gplots:

install.packages("gplots")

Use boxplot2() [in gplots]:

library("gplots")
# Box plot with annotation
boxplot2(len ~ dose, data = ToothGrowth,
         frame = FALSE)


# Put the annotation at the top
boxplot2(len ~ dose, data = ToothGrowth,
         frame = FALSE, top = TRUE)