Faceting splits one data set into panels so each group can be compared separately.

Program

Play the script to switch grouping strategies and count how many panels would appear.

facet_groups.R
group_choice <- 
region <- c("north", "south", "north", "east")
group <- c("region", "single", "pair")[group_choice]
facet <- switch(group, region = region, single = rep("all", length(region)), pair = c("A", "A", "B", "B"))
panels <- length(unique(facet))
label <- paste(group, panels, sep = ":")
cat(label, "\n", sep = "")
group_choice <- 
region <- c("north", "south", "north", "east")
group <- c("region", "single", "pair")[group_choice]
facet <- switch(group, region = region, single = rep("all", length(region)), pair = c("A", "A", "B", "B"))
panels <- length(unique(facet))
label <- paste(group, panels, sep = ":")
cat(label, "\n", sep = "")
group_choice <- 
region <- c("north", "south", "north", "east")
group <- c("region", "single", "pair")[group_choice]
facet <- switch(group, region = region, single = rep("all", length(region)), pair = c("A", "A", "B", "B"))
panels <- length(unique(facet))
label <- paste(group, panels, sep = ":")
cat(label, "\n", sep = "")
facet A facet key assigns each row to a panel.
unique panels `length(unique(facet))` counts how many panels are needed.
group strategy Changing the grouping strategy changes the chart layout without changing the data rows.