I have tabulated the results (OR, 95% CI) of logistic regression models and I want to show the odds ratio in a "forest plot-like" graph with zebra theme and sorted by sex (=group female or male).
structure(list(aOR = c(0.755657618643583, 1.62135330604067, 0.865398256316296,
0.727203230474939, 2.11334255563662, 0.898407262562538), confidence_lower = c(0.613593844349365,
1.35046132165669, 0.841880115298544, 0.6196490131542, 1.79796736338675,
0.877221949869505), confidence_upper = c(0.930613046191133, 1.94658410489249,
0.889573382749048, 0.853425934984244, 2.48403661179473, 0.920104210280172
), group = c("Female", "Female", "Female", "Male", "Male", "Male"
), labels = c("Age", "Diabetes", "BMI", "Age", "Diabetes", "BMI"
)), row.names = c(NA, -6L), class = "data.frame")
I started coding using ggplot. Thanks to another questions I found here, I discovered that in order to show the dots and bars grouped per sex, I need to factorize the labels.
This is my code:
#Factors
Variable_order <- c('Age', 'Diabetes', 'BMI')
df$labels = factor (df$labels, level=Variable_order)
#Define colours for dots and bars
dotCOLS = c("orchid2","dodgerblue2")
barCOLS = c("black","black")
#Plot
p <- ggplot (df, aes(x=aOR, xmin=confidence_lower, xmax=confidence_upper, y=labels, col=group, fill=group)) +
geom_linerange(linewidth=0, position=position_dodge(width = 0.5)) +
geom_vline(xintercept=1, lty=2) +
geom_point(size=3, shape=21, stroke = 0, position=position_dodge(width = 0.5)) +
scale_fill_manual(values=dotCOLS)+
labs(x="Odds ratio") +
scale_color_manual(values=barCOLS)+
coord_cartesian(ylim=c(1,4), xlim=c(-2.5, 4.5)) +
annotate("text", x=-1, y=4.5, label = "Reduce death") +
annotate("text", x=3, y=4.5, label = "Increase death") +
theme_classic()
print(p)
The result I want to achieve is this and as you can see I am far from it:
I found a similar question here [https://stackoverflow.com/questions/15420621/reproduce-table-and-plot-from-journal/20266137#20266137] however my problem is that the csv dataset is not downloadable anymore and I don't know how to reproduce the code.
My problem is that I need to group the ORs per group and I didn't find a solution here. Please help. I want to use ggplot because it is more customizable compared to other existing packages.