Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

facet titles repeated before/after ggbreaks #75

Open
kbstephe opened this issue Jan 24, 2025 · 0 comments
Open

facet titles repeated before/after ggbreaks #75

kbstephe opened this issue Jan 24, 2025 · 0 comments

Comments

@kbstephe
Copy link

kbstephe commented Jan 24, 2025

I am attempting to make a plot that has facets and uses ggbreak. My issue is that the facet titles are repeating before/after each break. Ideally, the facet title would appear just once, centrally, above each facet (row). Is this possible?

plot_data %>%
filter(School %in% schools_plot1) %>%
ggplot(aes(x = Date, group = School)) +
geom_line(data = . %>% filter(Date < break_start1),
aes(y = Attendance_NA), color = "#989898") +
geom_line(data = . %>% filter(Date > break_end1 & Date < break_start2),
aes(y = Attendance_NA), color = "#989898") +
geom_line(data = . %>% filter(Date > break_end2),
aes(y = Attendance_NA), color = "#989898") +
geom_point(aes(y = Attendance_NA), color = "#989898") +
geom_point(aes(y = Attendance_NA), shape = 21, stroke = 0.5, color = "black") +
geom_point(data = filter(plot_data,
School %in% schools_plot1 & Attendance < 10 | NA),
aes(y = 0), color = "red", size = 1, alpha = 0.5) +
labs(
x = "",
y = "Number of students attending school") +
theme_minimal() +
theme(
axis.text.x = element_text(angle = 45, hjust = 1, size = 12, color = "black"),
panel.grid.major.y = element_line(color = "#CCCCCC", size = 0.2),
panel.grid.minor.y = element_blank(),
panel.grid.minor.x = element_blank(),
axis.text.y = element_text(size = 12, color = "black", margin = margin(r = 5)),
axis.title.y = element_text(size = 14, color = "black", margin = margin(r = 10)),
strip.text = element_text(size = 12, color = "black", margin = margin(b = 10)),
strip.background = element_blank(),
panel.spacing.y = unit(1.2, "lines"),
legend.position = "none",
axis.text.x.top = element_blank()
) +
facet_wrap(~School, nrow = 5, scales = "free_y") +
scale_x_date(date_breaks = "1 week", date_labels = "%b %d", expand = c(0.05, 0)) +
scale_x_break(c(break_start1, break_end1, break_start2, break_end2), space = 1.2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant