16.7 Grouping vs. faceting
With faceting, each group is quite far apart in its own panel, and there is no overlap between the groups. This is good if the groups overlap a lot, but it does make small differences harder to see.
When using aesthetics to differentiate groups, the groups are close together and may overlap, but small differences are easier to see.
df <- data.frame(
x = rnorm(120, c(0, 2, 4)),
y = rnorm(120, c(1, 2, 1)),
z = letters[1:3]
)
ggplot(df, aes(x, y)) +
geom_point(aes(colour = z))
You can help the viewer make comparisons across facets with some thoughtful annotation.
In this example, we show the mean of every group in each panel.
df_sum <- df %>%
group_by(z) %>%
summarise(x = mean(x), y = mean(y)) %>%
rename(z2 = z)
ggplot(df, aes(x, y)) +
geom_point() +
geom_point(data = df_sum, aes(colour = z2), size = 4) +
facet_wrap(~z)
Alternatively, we could put all data points in each panel, and only colour the focal data.