Good afternoon,
I have an outcome y and two covariates e.g. sex and age. I want to plot two ggplot2 boxplots with the outcome y and sex. However, I would like before that "regress out" the effect of age. I read online that it could be done via plotting the residuals or coefficients. Which method do you prefer? Would below code be correct?
fit <- lm(y~ age,df)
df$Residual <- residuals(fit)
ggplot(data = df, aes(x=sex, y=scale(Residual))?
Thank you!