I'd like to force facet_wrap to fill from the top-left, but in such a way as to always fully fill the bottom row. (That is, from the top-left plus whatever horizontal offset is required to fully fill the bottom row.)
library(ggplot2)
n <- 1000
df <- data.frame(x=runif(n), y=rnorm(n), label=sample(letters[1:7], size=n, replace=TRUE))
df$label.rev <- factor(df$label, levels=sort(unique(df$label), decreasing=TRUE))
p <- ggplot(df, aes(x=x, y=y)) + geom_point()
p1 <- p + facet_wrap(~ label, ncol=3)
p2 <- p + facet_wrap(~ label, ncol=3, as.table=FALSE)
p3 <- p + facet_wrap(~ label.rev, ncol=3, as.table=FALSE)
p1: I'm happy with the left-to-right, top-to-bottom ordering of the labels, but I'd like the gap to be at the top left instead of the bottom right.
p2: Gap is now in the top row (top right rather than top left, unfortunately), but the label order is wrong.
p3: Similar to p2; attempts to fix the label order, and fails.
I'd like the facets to be ordered like this:
_ _ A
B C D
E F G
...so that there are axes along the entire bottom row, and because I think it would look better than the default. How can I do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…