Any way to customize facet position?

82 views
Skip to first unread message

Thiago V. dos Santos

unread,
Aug 20, 2020, 12:15:21 PM8/20/20
to ggplot2

I am plotting a ggplot2 graph that has an uneven number of facets. My plot currently looks something like this:

library(ggplot2)

df <- data.frame(group=c(1,1,2,2,3),
                 name=c('a','b','c','d','e'),
                 x=c(1,2,3,4,5),
                 y=c(2,3,4,5,6))
ggplot(df, aes(x,y)) + geom_point() + facet_wrap(~ name, ncol=3)

Note that the default positioning for the facets is:

a b c
d e

However, I would like to have a finer control on the positioning of the facets. Specifically, I would like to “center” the bottom two facets in order to distribute the void space more evenly on the sides of the plot.

In other words, the ideal placement for me would look like:

a b c
 d e

Is this something that can be achieved with ggplot2? How? Many thanks in advance.

Ben Bolker

unread,
Aug 20, 2020, 12:24:04 PM8/20/20
to ggp...@googlegroups.com

   I very much doubt it: I would check out the cowplot and patchwork packages.  In principle you can use these tools to do things like delete redundant axes, align plots, and place them how you want, but I expect it will be a nuisance.

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ggplot2/bc94732a-9dcf-4e40-b3a2-3d40b414d5b1n%40googlegroups.com.

Thiago V. dos Santos

unread,
Aug 20, 2020, 12:25:33 PM8/20/20
to ggplot2
Thanks Ben, I will check those out.

Anyway, this is a much needed feature in ggplot2.

Reply all
Reply to author
Forward
0 new messages