I want to make a few edits to a ggplot2 plot but I'm stuck.
For the headers, I want to combine the "Substance" labels (aka just one single header for "Alcohol", "Cigarettes" etc.) and then I remove the 0's and the 1's at the top entirely, since they're already labeled via the legend and are thus redundant.
I also want to move the markers of the same shape slightly closer together (aka each triangle should be closer to the other triangle, and same with the circles). That way it'll be easier to tell that they're supposed to be grouped together.
Finally, I want to remove the legend markers under "Color" and make the color of the word "Contemporaneous" gray to correspond with the figure. That way they can't be mixed up with the shape legend indicators.
I've tried strip.text.x = element_blank()
and a few other things but keep getting errors. Thank you!
Here's the figure I have created:
And here's my code:
ggplot(data = gfrdata,
aes(x = factor(model_cont0_lag1),
y = est,
ymin = lcl,
ymax = ucl,
color = model_cont0_lag1,
shape = model_year0_curr1)) +
geom_pointrange(size = 0.8) +
ylim(-24, 20) +
scale_color_manual(values = c(Contemporaneous = "gray60", Lagged = "gray0")) +
labs(color = 'Color', shape = 'Shape', x = ' ', y = 'Percent Difference (95% CI)') +
geom_errorbar(aes(ymin = lcl, ymax = ucl), width = 0.45, cex = 1) +
facet_grid(.~substance+model_year0_curr1, scale = 'free', space = 'free') +
geom_hline(yintercept = 0, linetype = 2) +
theme_classic() +
theme(panel.spacing=unit(0,"lines"),
axis.text.x = element_blank(), axis.ticks.x = element_blank(),
strip.background = element_blank(),
legend.position = "right", legend.direction = "vertical",
legend.text = element_text(color = "black"),
legend.title = element_text(face = "bold"))```