I first tidied the messy dataset to calculate percentages.
wholesample <- dataSDQcase_long %>%
filter(Severity != "NA") %>%
filter(Time_Month != "NA") %>%
dplyr::count(Time_Month, SDQ_caseness, Severity) %>%
group_by(Time_Month, SDQ_caseness) %>%
mutate(Percentage = (n / sum(n)) * 100) %>%
ungroup()
wholesample$Severity <- factor(wholesample$Severity, levels = c(0:1), labels = c("Unlikely", "Likely"))
I then used ggplot2 and geom_area to create the area graphs and set the background as transparent.
p <- ggplot(subset(wholesample, Severity == "Likely"),
aes(x = Time_Month, y = Percentage)) +
geom_area(stat = "identity", group = 1, color="#0B747A", fill="#0B747A", alpha = 0.2) +
coord_cartesian(ylim = c(0,50))+
labs(x = NULL, y = 'Percentage %') + facet_wrap(~ SDQ_caseness, ncol=5) +
theme(legend.title = element_blank(), legend.position="right") +
geom_vline(xintercept= 5, linetype="longdash", colour = "black") + # to create vertical lines
geom_vline(xintercept= 10.5, linetype="solid", colour = "black") +
theme(legend.title = element_blank(), legend.position="right") +
theme_blank() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill = "transparent",colour = NA),
plot.background = element_rect(fill = "transparent",colour = NA)
) # to create a transparent background
ggsave("children_mentalhealth.png", p, bg = "transparent", width = 17, height = 3.6)