I'm looking to add a second layer of grouping to the x-axis as show in the panel for Outcome A below. There should be two points for each estimate type (ITT vs TOT) that correspond to the label 3 or 12.
Here's my approach to get what you see, minus the edits to the Outcome A panel:
df %>%
ggplot(., aes(x=factor(estimate), y=gd, group=interaction(estimate, time), shape=estimate)) +
geom_point(position=position_dodge(width=0.5)) +
geom_errorbar(aes(ymin=gd.lwr, ymax=gd.upr), width=0.1,
position=position_dodge(width=0.5)) +
geom_hline(yintercept=0) +
ylim(-1, 1) +
facet_wrap(~outcome, scales='free', strip.position = "top") +
theme_bw() +
theme(panel.grid = element_blank()) +
theme(panel.spacing = unit(0, "lines"),
strip.background = element_blank(),
strip.placement = "outside")
Here's the toy data:
df <- structure(list(outcome = c("Outcome C", "Outcome C", "Outcome C",
"Outcome C", "Outcome B", "Outcome B", "Outcome B", "Outcome B",
"Outcome A", "Outcome A", "Outcome A", "Outcome A"), estimate = c("ITT",
"ITT", "TOT", "TOT", "ITT", "ITT", "TOT", "TOT", "ITT", "ITT",
"TOT", "TOT"), time = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L), .Label = c("3", "12"), class = "factor"),
gd = c(0.12, -0.05, 0.19, -0.08, -0.22, -0.05, -0.34, -0.07,
0.02, -0.02, 0.03, -0.03), gd.lwr = c(-0.07, -0.28, -0.11,
-0.45, -0.43, -0.27, -0.69, -0.42, -0.21, -0.22, -0.33, -0.36
), gd.upr = c(0.31, 0.18, 0.5, 0.29, 0, 0.17, 0.01, 0.27,
0.24, 0.19, 0.38, 0.3)), class = "data.frame", row.names = c(NA,
-12L))