I have this code for an effect size plot:
Outcome_order <- c('January', 'February', 'March', 'April')
### A
df1 <- data.frame(Outcome=c('January', 'February', 'March', 'April'),
OR=c(1.09, 1.13, 1.07, 1.12),
Lower=c(0.99, 1.02, 0.93, 1.09),
Upper=c(1.20, 1.25, 1.23, 1.14))
df1$group <- "C"
## B
df2 <- data.frame(Outcome=c('January', 'February', 'March', 'April'),
OR=c(1.08, 1.11, 1.05, 1.06),
Lower=c(1.00, 1.02, 0.92, 1.04),
Upper=c(1.17, 1.22, 1.19, 1.08))
df2$group <- "B"
## C
df3 <- data.frame(Outcome=c('January', 'February', 'March', 'April'),
OR=c(1.08, 1.13, 1.07, 1.11),
Lower=c(0.98, 1.01, 0.93, 1.08),
Upper=c(1.20, 1.27, 1.23, 1.36))
df3$group <- "A"
# combine the two datasets
combined = rbind(df1, df2, df3)
## factoring
combined$Outcome = factor (combined$Outcome, level=Outcome_order)
#define colours for dots and bars
barCOLS = c("#e6a7c9","#d05b9b","#FF9393")
dotCOLS = c("#e6a7c9","#bb357e","#FF9393")
p <- ggplot(combined, aes(x = Outcome, y = OR, ymin = Lower, ymax = Upper,
col = group, fill = group)) +
geom_linerange(size = 2, position = position_dodge(width = 0.5)) +
geom_hline(yintercept = 1, lty = 2) +
geom_point(size = 2, shape = 4, colour = "black", stroke = 0.5,
position = position_dodge(width = 0.5)) +
scale_fill_manual(values = barCOLS) +
scale_color_manual(values = dotCOLS) +
scale_x_discrete(name = "") +
scale_y_continuous(name = "Adjusted Odds Ratio", limits = c(0.75, 2.5)) +
coord_flip() +
theme_minimal() +
theme(
axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 12),
legend.text = element_text(size = 14),
legend.title = element_text(size = 16)
)
print(p)
It looks like this:
I would like each month within the plot to have a different background colour - alternating between light grey and white. How would I do this? Loose example here:
Many thanks, any help appreciated!