the following example creates a ggplot with the 4 panels “A”, “B”, “C”, “D” in one row.
I figured out how to plot these 4 panels in one column. However, what still remains a mystery is how to arrange the 4 panels so that “A” and “B” are in the first row and “C” and “D” are put in a separate (second) row?
Here’s my code:
df <- data.frame(
x = rep(rep(1:10, each=10), 2),
y = rep(rep(1:10, 20), 2),
grid = rep(LETTERS[1:4], each=100)
)
ggplot(df, aes(x = x, y = y)) +
geom_point() +
facet_grid(. ~ grid, scales = "free")
Use
facet_wrapinstead offacet_grid: