• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

How to Make Notched boxplots with ggplot2

datavizpyr · August 9, 2022 ·

In this tutorial, we will learn how to make notched boxplots using ggplot2 in R. Notched boxplot is a variant of boxplot that helps comparing boxplots from different groups in a plot. “Notch” refers to the narrowing of the box around the median of the boxplot.

If we are interested in difference between medians of two boxplots, two boxplot with overlapping notches would suggest that there is no differences between the two groups plotted as boxplots. On the other hand if the notoches between two boxplots do not overlap then we can be confident that their median is significantly different from each other.

Let us get started by loading the packages needed, in this case we load tidyverse suite and plamer penguin dataset.

library(tidyverse)
library(palmerpenguins)
theme_set(theme_bw(16))

First, let us go ahead and make a simple boxplot using geom_boxplot() showing the body mass across three penguin species.

penguins %>%
  drop_na() %>%
  ggplot(aes(x=species, y=body_mass_g, fill=species))+
  geom_boxplot()+
  theme(legend.position = "none")
ggsave("boxplot_ggplot.png")
boxplot with ggplot2
boxplot with ggplot2

Notched Boxplot in ggplot2

To make a notched boxplot, we need to specify notch=TRUE as argument to geom_boxplot().

penguins %>%
  drop_na() %>%
  ggplot(aes(x=species,y=body_mass_g, fill=species))+
  geom_boxplot(notch=TRUE)+
  theme(legend.position = "none")
ggsave("how_to_make_notched_boxplot_ggplot.png")
Notched Boxplot in ggplot2
How to make notched boxplot in ggplot

In the above notched boxplot we can see that notches for Adelie and Chinstrap overlap suggesting that there is no difference in median values of body mass between them. However, the notch for Gentoo does not overlap with neither of the other two groups suggesting that median body mass of Gentoo is sificantly different from the other two species.

Related posts:

Customizing Mean mark to boxplot with ggplot2How To Show Mean Value in Boxplots with ggplot2? Scatterplot with marginal multi-histogram with ggExtraHow To Make Scatterplot with Marginal Histograms in R? Default ThumbnailHow to Move Facet strip label to the bottom Default ThumbnailHow to change axis tick label size in ggplot2

Filed Under: ggplot2, R Tagged With: Notched Boxplot ggplot2

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

Copyright © 2025 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version