ggplot2 facet_grid arrange panels
12,569
Use facet_wrap
instead of facet_grid
:
library(ggplot2)
ggplot(df, aes(x = x, y = y)) +
geom_point(aes(colour=grid)) +
facet_wrap(~ grid, scales = "free")
Author by
user969113
Updated on July 12, 2022Comments
-
user969113 almost 2 years
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")