Ggplot2 boxplot parameters



A boxplot summarizes the distribution of a continuous variable. The ggplot2 library allows to build it thanks to the geom_boxplot function. This function offers several options to custom its appearance and this post is dedicated to them.

Boxplot Section Boxplot pitfalls

This chart extends the previous most basic boxplot described in graph #262.

It describes the option you can apply to the geom_boxplot() function to custom the general chart appearance.

Note on notches: useful to compare groups: if no overlap between 2 groups, medians are significantly different.

# Load ggplot2
library(ggplot2)
 
# The mpg dataset is natively available
#head(mpg)
 
# geom_boxplot proposes several arguments to custom appearance
ggplot(mpg, aes(x=class, y=hwy)) + 
    geom_boxplot(
        
        # custom boxes
        color="blue",
        fill="blue",
        alpha=0.2,
        
        # Notch?
        notch=TRUE,
        notchwidth = 0.8,
        
        # custom outliers
        outlier.colour="red",
        outlier.fill="red",
        outlier.size=3
    
    )

Related chart types


Violin
Density
Histogram
Boxplot
Ridgeline



Contact

This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message on Twitter, or send an email pasting yan.holtz.data with gmail.com.

Github Twitter