I just add geom_subtile()
and geom_subrect()
function in package ggalign to subdivide rectangles with shared borders into a grid.
df <- tibble::tibble(
id = c(LETTERS[1:6], LETTERS[1:5]),
value = c(paste0("V", 1:6), paste0("V", 1:5)),
group = c(rep("group_1", 6), rep("group_2", 5))
)
library(ggalign)
ggplot(df, aes(x = id, y = value, fill = group)) +
geom_subtile()
It can do more:
## arranges by row
ggplot(data.frame(value = letters[seq_len(5)])) +
geom_subtile(aes(x = 1, y = 1, fill = value))
## arranges by column
ggplot(data.frame(value = letters[seq_len(9)])) +
geom_subtile(aes(x = 1, y = 1, fill = value), byrow = FALSE)
## one-row
ggplot(data.frame(value = letters[seq_len(4)])) +
geom_subtile(aes(x = 1, y = 1, fill = value), direction = "h")
## one-column
ggplot(data.frame(value = letters[seq_len(4)])) +
geom_subtile(aes(x = 1, y = 1, fill = value), direction = "v")