I have some data, which has integer x-value from small to quite large. I want to split the x-axis in intervals and I am currently doing as exemplified below. However:
- The group-splitting seems a bit hack'ish, is there a more tidy way to do this?
- The last pane gets stretched distorting the overview, how can this be avoided?
# Reproducible example set.seed(352053) # Set example data d <- tibble(x = seq(from = 1, to = 922), y = rnorm(n = length(x))) # First plot, no interval split d %>% ggplot(aes(x = x, y = y)) + geom_col() + scale_x_continuous(expand = c(0, 0)) + theme_bw() ggsave(filename = "first_plot_no_split.png", width = 10, height = 6, dpi = 72)
# Set groups for interval splitting d <- d %>% mutate(y_i = rep(x = 1:10, each = 100)[1:length(x)]) # Second plot, with interval splitting d %>% ggplot(aes(x = x, y = y)) + geom_col() + scale_x_continuous(expand = c(0, 0)) + theme_bw() + facet_wrap(vars(y_i), ncol = 1, scales = "free_x") + theme(strip.background = element_blank(), strip.text.x = element_blank()) ggsave(filename = "second_plot_with_split.png", width = 6, height = 10, dpi = 72)