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)