Dear all,
I have difficulties with the following task: I want to plot the predicted effect of a continuous variable in a binary logistic regression analysis. This is easy. However, if I want plot the effect of two variables on the same dependent, I can only do this next to each other, but I want to have it overlapping.
To demonstrate this, I use this example data on sex and weight/height (of course there is no rational behind this).
# dataframe with two groups (males/females) and respective weight and height
set.seed(1234)
df <- data.frame(
sex=factor(rep(c("0", "1"), each=200)),
weight=round(c(rnorm(200, mean=55, sd=5),
rnorm(200, mean=65, sd=5))),
height=round(c(rnorm(200, mean=160, sd=10),
rnorm(200, mean=170, sd=10)))
)
library(ggplot2)
library(sjPlot)
library(ggpubr)
lm1 <- glm(sex ~ weight, data=df, family="binomial")
lm2 <- glm(sex ~ height, data=df, family="binomial")
# Current version: Plot them next to each other.
p1 <- plot_model(lm1, type="pred", term="weight")
p2 <- plot_model(lm2, type="pred", term="height")
ggarrange(p1,p2)
# Desired version: Plot them overlapping over each other (potentially without confidence intervals)
Thank you for your help!