Hi there!
I have a very long plot that I'd like to split into several sub-plots to make it readable.
To my data.frame, I added an additional variable to make sub-groups for wrapping and used facet_wrap
to make multiple plots. However, due to the 'free_x' scale, the last plot looks weird. I want it to have the same x:y ratio with the space at the right being just blank.
suppressMessages({
library(tibble)
library(dplyr)
library(ggplot2)
})
df <- tibble(x = 1:90,
y = sample(x = LETTERS, size = 90, replace = TRUE)) %>%
mutate(facet_group = (x - 1) %/% 20)
ggplot(df) +
geom_tile(aes(x = x,
y = 1,
fill = y)) +
facet_wrap(facets = vars(facet_group),
scales = 'free_x',
ncol = 1) +
theme_bw() +
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
legend.position = 'None')
Created on 2023-09-15 with reprex v2.0.2
Thanks in advance.