I found a problem with the naming of panels (naming within the table grob) with facet_wrap; the panels are named in the wrong order. This is not really an issue in the normal course of ggplot2 use, but is confusing for people delving into the tableGrob / gtable structure of a ggplot2 plot.
For example, if you create a plot using facet_wrap() to lay out 2 rows and 3 columns of facets, the panel "cells" of the gtable are named (sensibly) panel-1-1, panel-2-1, panel-3-1, panel-1-2, panel-2-2, and panel-3-2. But the order of these names is wrong, so that the plot as laid out looks like this:
I found a problem with the naming of panels (naming within the table grob) with
facet_wrap
; the panels are named in the wrong order. This is not really an issue in the normal course of ggplot2 use, but is confusing for people delving into thetableGrob
/gtable
structure of a ggplot2 plot.For example, if you create a plot using
facet_wrap()
to lay out 2 rows and 3 columns of facets, the panel "cells" of the gtable are named (sensibly)panel-1-1
,panel-2-1
,panel-3-1
,panel-1-2
,panel-2-2
, andpanel-3-2
. But the order of these names is wrong, so that the plot as laid out looks like this:I expected the ordering of names to correspond to this layout:
Here is the code to reproduce the bug:
Created on 2024-09-05 with reprex v2.1.0
If you look carefully at the output above, you will see how the naming of the panels doesn't correspond to the layout as indicated by
t
/l
/b
/r
.In the development version of
ggplot2
, the issue is inR/facet-.R
, lines 238-243:I believe these lines should instead be
or
(with the two
rep
lines switched) depending on whether you want the syntax to bepanel-col-row
orpanel-row-col
.