I would like to align the strata boxes to the borders of the graph in ggalluvial plots, and cannot find the way to customize my plot accordingly.
I could not find the way to adjust their position using hjust
, it only moves the texts.
Here is my code :
library(dplyr)
library(ggplot2)
library(ggalluvial)
alluv2 <- nplus %>%
group_by(dpth_loc.factor, N_post_CNA.factor) %>%
summarise(obs=n(), .groups="keep") %>%
ggplot(aes(y=obs,
axis1=dpth_loc.factor,
axis2=N_post_CNA.factor)) +
geom_alluvium(aes(fill=N_post_CNA.factor))+
geom_stratum(width=1/4, alpha =0.8)+
geom_text(stat = "stratum",
aes(label = after_stat(stratum))) +
scale_x_discrete(limits = c("Depth Location", "N post NAC Status"),
expand = c(0.15, 0.09)) +
scale_fill_manual(values = c("#d4d5b3", "#60436e")) +
theme_minimal()+
theme(legend.position="none",
axis.text.x = element_text(size = 12, face = "bold"),
axis.title.y = element_blank())
and the resulting graph :