plot_stratified_results <-
function(data_for_plotting, colors, labels, title, plot_name, path, ...) {
plot <-
#Create a main plot
ggplot(
data_for_plotting,
aes(Exposure, Estimate)) +
# Mark IRR estimates as points with 95% CI
geom_pointrange(
aes(ymin = conf_low,
ymax = conf_high,
color = group),
position = position_dodge(0.5),
size = 0.3) +
# Add line marking IRR = 1
geom_hline(
yintercept = 1,
linetype = "dashed",
color = "gray") +
# Add line between SDQ ext and int scores
geom_vline(
xintercept = 4.5,
linetype = "dashed",
color = "gray") +
#Add labels
labs(
title = "",
x = "",
y = "Incidence rate ratio (IRR)",
color = "Sub-population:") +
# Add colors and lables to the legend
scale_color_manual(
values = colors,
labels = labels) +
# Change y lim
ylim(...) +
xlab("") +
geom_text(x = 2.5,
y = 0.5,
label = "SDQ externalising") +
geom_text(x = 5.05,
y = 0.5,
label = "SDQ internalising") +
theme_classic() +
theme(
legend.position = c(.5, 0.85),
panel.background = element_rect(
colour = "black",
size = 1),
legend.box.background = element_rect(
color = "black",
fill = "grey90",
size = 1,
linetype = "solid"),
legend.key.size = unit(0.25, "cm"),
legend.key.width = unit(1, "cm"))
#save the plot to a file
ggsave(plot_name, plot = last_plot(), path = path, device = "jpeg", scale = 1, width = 20, height = 18, units = "cm", dpi = 150, limitsize = TRUE)
return(plot)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.