tidyverse / tidyverse/ggplot2

`layer (layout)` does not work with `facet_wrap` when used on integer vectors

Open
#6,883 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

facets :gem:
Dominant language
R
Stars
7k
Forks
2.1k
Avg merge
59m
Merged PRs (30d)
2

Description

Hi!

When experimenting with some of the new features introduced in version 4.0 and later, I encountered an unexpected behavior. According to the ggplot2 documentation, when the layer (layout) parameter is used in conjunction with facet_wrap, both integer vectors and the ‘fixed’ argument are valid.
https://ggplot2.tidyverse.org/reference/facet_wrap.html#:~:text=Layer%20layout,across%20every%20panel.

Layer layout
The layer(layout) argument in context of facet_wrap() can take the following values:

  • NULL (default) to use the faceting variables to assign panels.
  • An integer vector to include selected panels. Panel numbers not included in the integer vector are excluded.
  • "fixed" to repeat data across every panel.

However, based on the results, it appears that the integer values do not seem to have any effect on the panel markers.

library(ggplot2)
ggplot(mpg, aes(displ, hwy)) +
  geom_point(layout = 'fixed',colour = "grey", alpha = 0.3) +
  geom_point()+
  facet_wrap(vars(class), axes = "all", axis.labels = "all_y" )


ggplot(mpg, aes(displ, hwy)) +
  geom_point(layout = c(1,2,3),colour = "grey", alpha = 0.3) +
  geom_point()+
  facet_wrap(vars(class), axes = "all", axis.labels = "all_y" )

Created on 2026-07-28 with reprex v2.1.1

Not sure if it's because I'm using it wrong, or if this is a bug? If it's the former, could you please tell me the correct way to use it?

All the best,
Hu

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the two reprexes in the issue and inspect facet_wrap() and layer(layout) handling. Done means that layout = c(1, 2, 3) limits the layer to those panels as documented, with regression coverage for the integer-vector behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.