Last updated on August 14, 2025
Do long strip labels in facet_wrap() break your ggplot2 plots? When labels are too long, they can become unreadable. This tutorial shows you how to automatically wrap them. You’ll learn to use a labeller function to control the width of your facet labels, keeping your visualizations clean and easy to read.

Let us load tidyverse.
library(tidyverse) theme_set(theme_bw(16))
We will start by creating a small dataframe to use for making a boxplot with facets. One the groups in the facet has a really long group name.
df <- data.frame(measurement = rnorm(20,mean=30),
group = c(rep('A really long group variable name that needs to be wrapped',10),
rep('group1',10)),
sex = c(rep(c('M','F'),10)))
df %>% head()
measurement group sex
1 29.78323 A really long group variable name that needs to be wrapped M
2 29.80423 A really long group variable name that needs to be wrapped F
3 31.88631 A really long group variable name that needs to be wrapped M
4 30.95879 A really long group variable name that needs to be wrapped F
5 29.69200 A really long group variable name that needs to be wrapped M
6 29.45745 A really long group variable name that needs to be wrapped F
Let us make a boxplot using facet_wrap() function in ggplot2. In this plot we can see that one of the strip label is very long and goes over the strip box in the facet. And that makes the label unreadable.
df %>%
ggplot(aes(sex, measurement, color = sex)) +
geom_boxplot() +
facet_wrap(~group) +
theme(legend.position = "none")
ggsave("facet_wrap_example_with_long_strip_label.png")

How to wrap a facet plot dynamically with long strip label
ggplot2 has useful labeller functions for formatting the strip labels of facet grids and wraps. To wrap long strip label into multiline label within the facet, we can use the labeller – label_wrap_gen() function that specifies the width of the label.
df %>%
ggplot(aes(sex, measurement, color = sex)) +
geom_boxplot() +
facet_wrap(~group, labeller = label_wrap_gen(24))+
theme(legen.position="none")
ggsave("wrapping_the_long_strip_label_with_labeller_in_facet_wrap.png")
With the use of the labeller, we have the label wrapped dynamically within the facet as we wanted.

Explore the Complete ggplot2 Guide
35+ tutorials with code: scatterplots, boxplots, themes, annotations, facets, and more—tested and beginner-friendly.
Visit the ggplot2 Hub → No fluff—just code and visuals.


