Number of rows / columns for facet wrap in AlgebraOfGraphics

Does anyone know of an easy way to specify the number of rows / columns when facet wrapping in AOG?

E.g., in the following example I’d like to specify a 3x2 layout instead of 2x3:

df = (x=rand(100), y=rand(100), l=rand(["a", "b", "c", "d", "e"], 100))
plt = data(df) * mapping(:x, :y, layout=:l)

I thought maybe there was some keyword argument that you could pass to draw, like

draw(plt, facet=(;nrow=3))

But that doesn’t seem to be possible. Could I override the layout manually somehow?

1 Like

@piever told me there was a method to do it by passing a vector of position tuples as a palette, but I never tried it. Maybe it’s worth opening an issue for it?

1 Like

Yeah, for now you have to manually specify a list of positions, eg

palettes = (layout=[(1, 1), (1, 2), (2, 1), (2, 2), (3, 1)],)
draw(plt, palettes)

Definitely worth it to add a more straightforward solution to this. I was thinking something like

palettes = (layout=wrap(cols=3),)
1 Like

Thanks, that’s already very helpful. I would probably have expected the option under facet instead of palettes but the palettes = (layout=wrap(cols=3),) also would be nice.

I created a PR to add an example with the manually specified layout to the gallery.