Hi,
I did linear regression analysis between the response variable(y) and
predictor variables in the surgical data set considering pindex as a confounding variable.
I aim to plot the response variable(y) against the experimentally determined values of the predictor variables and to this end, I am Successful. However, could not able to indicate the estimated regression and p-value in the ggplot2
In the code below, trying to do the analysis and the plot.
It would be much appreciated if someone could show me how to indicate the estimated regression and p-values in the ggplot2.
library(olsrr)
library(tidyverse)
library(reshape2)
data(surgical)
## Regression
pre1 <-setdiff(names(surgical), c("y", "pindex"))
mod_dres<-NULL
for (j in pre1) {
model <- lm(y ~ pindex + get(j), data = surgical)
bmodel <- broom::tidy(model)
bmodel$term[3]<-j
bmodel<-bmodel[3,]
mod_dres<-rbind(mod_dres,bmodel)
}
mod_dres
## Matching the significant variables with the orginal data and reshaping
pre1.plot = melt(surgical[,-c(2)], id.vars='y') %>%
dplyr::filter(variable %in% mod_dres$term)
## plot the predictors varaibles
ggplot(pre1.plot) +
geom_jitter(aes(value,y, colour=variable),
colour="darkorange", size = 3) +
geom_smooth(aes(value,y, colour=variable),
method=lm, se=FALSE, colour="darkorange") +
theme_minimal() +
theme(axis.title = element_text(size = 16,face="bold", colour = "black"),
axis.text = element_text(size = 16,face="bold", colour = "black"),
axis.line = element_line(colour='black'),
axis.ticks = element_line(colour='black'),
plot.title = element_text(hjust = 0.5,size=18,face="bold"),
legend.position = "bottom",
legend.title = element_text(color = "Black", size = 9, face = "bold"),
legend.text=element_text(color = "Black", size = 9, face = "bold"),
strip.text.x = element_text(size = 16,face="bold", colour = "black")) +
labs(x = "value",title = " ") +
facet_wrap(~variable, scales="free_x",nrow = 2, ncol = 4) +
theme(panel.background = element_rect(fill = "white", colour = "black"),
strip.background = element_rect(fill = "white", colour = "black"),
legend.key = element_blank(),
legend.title = element_blank())
Thank you!