Visualization Workflows
Facet Groups
Count Small Multiples
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
Replay: real traced execution (multi-file project)
group_choice <- 2
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 <- 1
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 <- 3
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 ← 2
1group_choice <- 22region <- c("north", "south", "north", "east")values this step2group_choiceregion ← north, south, north, east
1group_choice <- 22region <- c("north", "south", "north", "east")3group <- c("region", "single", "pair")[group_choice]values this stepnorth, south, north, eastregiongroup ← single
2region <- c("north", "south", "north", "east")3group <- c("region", "single", "pair")[group_choice]4facet <- switch(group, region = region, single = rep("all", length(region)), pair = c("A", "A", "B", "B"))values this stepsinglegroup2group_choicefacet ← all, all, all, all
3group <- c("region", "single", "pair")[group_choice]4facet <- switch(group, region = region, single = rep("all", length(region)), pair = c("A", "A", "B", "B"))5panels <- length(unique(facet))values this stepall, all, all, allfacetsinglegrouppanels ← 1
4facet <- switch(group, region = region, single = rep("all", length(region)), pair = c("A", "A", "B", "B"))5panels <- length(unique(facet))6label <- paste(group, panels, sep = ":")values this step1panelsall, all, all, allfacetlabel ← single:1
5panels <- length(unique(facet))6label <- paste(group, panels, sep = ":")7cat(label, "\n", sep = "")values this stepsingle:1labelsinglegroup1panelscat(label, " ", sep = "")
6label <- paste(group, panels, sep = ":")7cat(label, "\n", sep = "")outputsingle:1values this stepsingle:1label
group_choice ← 1
1group_choice <- 12region <- c("north", "south", "north", "east")values this step1group_choiceregion ← north, south, north, east
1group_choice <- 12region <- c("north", "south", "north", "east")3group <- c("region", "single", "pair")[group_choice]values this stepnorth, south, north, eastregiongroup ← region
2region <- c("north", "south", "north", "east")3group <- c("region", "single", "pair")[group_choice]4facet <- switch(group, region = region, single = rep("all", length(region)), pair = c("A", "A", "B", "B"))values this stepregiongroup1group_choicefacet ← north, south, north, east
3group <- c("region", "single", "pair")[group_choice]4facet <- switch(group, region = region, single = rep("all", length(region)), pair = c("A", "A", "B", "B"))5panels <- length(unique(facet))values this stepnorth, south, north, eastfacetregiongrouppanels ← 3
4facet <- switch(group, region = region, single = rep("all", length(region)), pair = c("A", "A", "B", "B"))5panels <- length(unique(facet))6label <- paste(group, panels, sep = ":")values this step3panelsnorth, south, north, eastfacetlabel ← region:3
5panels <- length(unique(facet))6label <- paste(group, panels, sep = ":")7cat(label, "\n", sep = "")values this stepregion:3labelregiongroup3panelscat(label, " ", sep = "")
6label <- paste(group, panels, sep = ":")7cat(label, "\n", sep = "")outputregion:3values this stepregion:3label
group_choice ← 3
1group_choice <- 32region <- c("north", "south", "north", "east")values this step3group_choiceregion ← north, south, north, east
1group_choice <- 32region <- c("north", "south", "north", "east")3group <- c("region", "single", "pair")[group_choice]values this stepnorth, south, north, eastregiongroup ← pair
2region <- c("north", "south", "north", "east")3group <- c("region", "single", "pair")[group_choice]4facet <- switch(group, region = region, single = rep("all", length(region)), pair = c("A", "A", "B", "B"))values this steppairgroup3group_choicefacet ← A, A, B, B
3group <- c("region", "single", "pair")[group_choice]4facet <- switch(group, region = region, single = rep("all", length(region)), pair = c("A", "A", "B", "B"))5panels <- length(unique(facet))values this stepA, A, B, Bfacetpairgrouppanels ← 2
4facet <- switch(group, region = region, single = rep("all", length(region)), pair = c("A", "A", "B", "B"))5panels <- length(unique(facet))6label <- paste(group, panels, sep = ":")values this step2panelsA, A, B, Bfacetlabel ← pair:2
5panels <- length(unique(facet))6label <- paste(group, panels, sep = ":")7cat(label, "\n", sep = "")values this steppair:2labelpairgroup2panelscat(label, " ", sep = "")
6label <- paste(group, panels, sep = ":")7cat(label, "\n", sep = "")outputpair:2values this steppair:2label
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.