• 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
  • Seaborn
  • Matplotlib
  • ggplot2
  • Altair
  • About
    • Privacy Policy
  • Visualizing Activation Functions in Neural Networks
  • Confusion Matrix Calculator
  • Visualizing Dropout Rate in Neural Network
  • Visualizing Loss Functions in Neural Networks
  • Show Search
Hide Search

How to wrap long strip labels in facet_wrap

datavizpyr · February 22, 2024 ·

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.

How to wrap long titles in a facet plot
How to wrap long titles in a facet plot

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
How to wrap a facet plot dynamically with long strip label

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.

Wrap a long strip label in a facet plot with labeller
Wrap a long strip label in a facet plot with labeller

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.

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? ggforce geom_circle(): Annotate with a circleHow To Annotate a Plot with Circle in R Default ThumbnailHow to Make Axis Text Bold in ggplot2

Filed Under: ggplot2, R Tagged With: wrap long strip label

Primary Sidebar

Python & R Viz Hubs

  • Seaborn Guide & Cookbook
  • ggplot2 Guide & Cookbook
  • Matplotlib Guide & Cookbook
  • Confusion Matrix Calculator
  • Visualizing Activation Functions
  • Visualizing Dropout
  • Visualizing Loss Functions

Buy Me a Coffee

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

Go to mobile version