Is there a canonical way to add facet titles within facet_grid
? Or a way to specific row labels in facet_wrap
? (Without geom_text
, geom_label
, or grob manipulation.)
Consider:
dat <- data.frame(rowInd = paste0("R", c(1, 2, 2, 3, 3, 3)), colInd = paste0("C", c(1, 1, 2, 1, 2, 3)),
facetName = c("1-10", "60-70", "80-90", "100-110", "120-130", "140-150"), val=1:6)
dat
# rowInd colInd facetName val
# 1 R1 C1 1-10 1
# 2 R2 C1 60-70 2
# 3 R2 C2 80-90 3
# 4 R3 C1 100-110 4
# 5 R3 C2 120-130 5
# 6 R3 C3 140-150 6
Direct plots give:
library(ggplot2)
ggplot(dat, aes(x=1, y=val)) + facet_grid(rowInd ~ facetName, switch="y") # 1
ggplot(dat, aes(x=1, y=val)) + facet_wrap(rowInd ~ facetName) # 2
ggplot(dat, aes(x=1, y=val)) + facet_grid(rowInd ~ colInd, switch="y") # 3
Where:
- includes the row and facet labels I want, but not all facet labels apply to all rows;
- correctly associates a row-label (
"R1"
) with a facet label, and one label per facet, but loses the row affiliation between facets; - loses facet labels.
Ultimately I'm trying to do something akin to one of the below:
I can "fill out" the data if needed (perhaps to facilitate the right plot), though it would be great to have them automatically hollow-plots or empty space.