So I have 1 measured variabel multiple times in 4 groups of which 1 group is the refernce group where I want to make a regression plot to with the other 3 groups. How do generate that? I see lots of examples of 2 variables plotted in groups but not what I mean (like: https://community.rstudio.com/t/multiple-linear-regression-lines-in-a-graph-with-ggplot2/9328)
This my df:
df <- data.frame("Variabel" = c(1,2,3,5,6,6,3,5,8,7,4,1,3,6,8,5),
"group" = c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4))
And her my lin regression code
#display regression formula in plot
my.formula <- y ~ x
LM_plot <- ggplot(df, aes(x=...,y=...., shape=group, colour=group, fill=group))+
geom_point(shape=21,size=4,colour = "black" ,alpha=0.5)+
geom_smooth(method="lm",alpha=0.3,color="blue",fill="grey", formula = my.formula)+
geom_abline(intercept=0,slope=1,size=0.5,linetype="dashed",color="black")+
theme_bw(base_rect_size = 0.2) +
labs(x = "Group 1", y = "Group 2, 3 and 4") +
ggtitle("Title") +
stat_poly_eq(aes(label = paste0("atop(", ..eq.label.., ",", ..rr.label.., ")")),
formula = my.formula,
parse = TRUE)