In our study, we aim to investigate the evolution of blood pressure (variable DIASTO) over time. Time is measured based on the treatment modification date (variable DELAI_SWITCH). The objective is to observe if there is a change in the evolution before and after the treatment modification. I needed to employ a two-slope model for this purpose. To achieve this, I utilized the following functions:
Delai = 0
DelaiNeg <- function(x, Delai) ifelse(x < Delai, x, 0)
DelaiPos <- function(x, Delai) ifelse(x < Delai, 0, x)
To create the following model, where PATIENT represents the identity of each patient:
model_Diasto <- lmer(DIASTO ~ DelaiNeg(DELAI_SWITCH, Delai) + DelaiPos(DELAI_SWITCH, Delai) + (1 | PATIENT), data = IeDEA_BP_Switch)
Everything is functioning well for now. And it gives us this : (https://i.stack.imgur.com/5FyA3.png)
which is nicely represented by :
ggplot(IeDEA_BP_Switch, aes(x = DELAI_SWITCH, y = DIASTO)) +
geom_point(color="royalblue",alpha=0.1) +
geom_line(aes(y = predicted_Diasto), color = "red", linetype = "dashed",size=1.1)`

It gets complicated when i try to add some adjustment variable to the model with interaction with DELAI_SWITCH.
Everything works fine when i try this model with an adjustment and interaction on SEX or with AGE
model_Diasto <- lmer(DIASTO ~ DelaiNeg(DELAI_SWITCH, Delai) + DelaiPos(DELAI_SWITCH, Delai) + SEX +(DelaiNeg(DELAI_SWITCH, Delai):SEX)+(DelaiPos(DELAI_SWITCH, Delai):SEX)+(1 | PATIENT), data = IeDEA_BP_Switch,REML=0)
The ggplot of predicted estimates also works fine
When I try to model some adjustment and interaction on AGE and on SEX, the model works fine, with these estimates :
model_Diasto <- lmer(DIASTO ~ DelaiNeg(DELAI_SWITCH, Delai) + DelaiPos(DELAI_SWITCH, Delai) +AGE_Switch +(DelaiNeg(DELAI_SWITCH, Delai):AGE_Switch)+(DelaiPos(DELAI_SWITCH, Delai):AGE_Switch)+
SEX +(DelaiNeg(DELAI_SWITCH, Delai):SEX)+(DelaiPos(DELAI_SWITCH, Delai):SEX)+(1 | PATIENT), data = IeDEA_BP_Switch,REML=0)
(https://i.stack.imgur.com/OG5VN.png)
But the ggplot geom_line goes crazy :

I tried with geom_smooth, but realised that the graph didn't properly fit the estimates of the model (for example intercept was wrong..).
If you guys have an idea of how to plot these kind of linear mixed model I would really appreciate it.
I tried several times and looked for answers on Stack Overflow. Some use geom_smooth, which does not seem to fit the estimates in my case. And I've seen no post with the geom_line going crazy as it does for me.