ggplot2 boxplot from continuous variable



A boxplot summarizes the distribution of a continuous variable. This post explains how to build a boxplot with ggplot2 where categories are actually bins of a numeric variable. It is sometimes useful to study the relationship between 2 nnumeric variables.

Boxplot Section Boxplot pitfalls

Let’s say we want to study the relationship between 2 numeric variables. It is possible to cut on of them in different bins, and to use the created groups to build a boxplot.

Here, the numeric variable called carat from the diamonds dataset in cut in 0.5 length bins thanks to the cut_width function. Then, we just need to provide the newly created variable to the X axis of ggplot2.

Related chart types


Violin
Density
Histogram
Boxplot
Ridgeline



❤️ 10 best R tricks ❤️

👋 After crafting hundreds of R charts over 12 years, I've distilled my top 10 tips and tricks. Receive them via email! One insight per day for the next 10 days! 🔥