I am creating a figure that shows 4 outcome beta's + CI lines per variable.
I want to more clearly show that the 4 plotted points (outcome) and lines (CIs) relate to each variable.
Therefore, I am curious how I might 1) make clearer panels or grid changes to show which 4 outcomes relate to which variable OR 2) Create brackets around the variable on the y axis?
Code and figure below.
library(tidyverse)
library(viridis)
#> Loading required package: viridisLite
df <- tribble(
~var, ~gender, ~outcome, ~est, ~l95, ~u95,
"A", "Men", "X", 0.2, 0.1, 0.3,
"A", "Men", "Y", 0.3, 0.25, 0.35,
"B", "Men", "X", -0.4, -0.5, -0.3,
"B", "Men", "Y", -0.45, -0.5, -0.4,
"A", "Women", "X", 0.4, 0.3, 0.5,
"A", "Women", "Y", 0.6, 0.55, 0.65,
"B", "Women", "X", -0.1, -0.2, 0,
"B", "Women", "Y", -0.3, -0.4, -0.2,
"A", "Men", "Z", 0.2, 0.1, 0.3,
"A", "Men", "AA", 0.3, 0.25, 0.35,
"B", "Men", "Z", -0.4, -0.5, -0.3,
"B", "Men", "AA", -0.45, -0.5, -0.4,
"A", "Women", "Z", 0.4, 0.3, 0.5,
"A", "Women", "AA", 0.6, 0.55, 0.65,
"B", "Women", "Z", -0.1, -0.2, 0,
"B", "Women", "AA", -0.3, -0.4, -0.2
)
df %>%
ggplot(aes(x=est, y=var, color=outcome)) +
geom_point(position = position_dodge2(width = 1.0)) +
scale_y_discrete(limits=rev, expand=c(0, 0)) +
scale_color_viridis_d() +
geom_linerange(aes(xmin=l95, xmax=u95),
position = position_dodge2(width=1.0)) +
geom_vline(xintercept = 0, linetype = "dashed") +
facet_grid(~ gender) +
theme_minimal() +
theme(plot.title.position = "plot",
plot.title = element_text(face="bold"),
legend.position = "top",
strip.text = element_text(face="bold")) +
labs(y = NULL,
x = "Standardized Beta",
title = "My cool plot shows this thing",
subtitle = "More important details, 95% confidence intervals",
caption = "Even more important details")

Created on 2021-06-03 by the reprex package (v2.0.0)


