- Operating System: Windows 10
- brms Version: 2.9.0
This might be more of a ggplot question. Not sure. I am creating a marginal effects plot for a 3-way interaction. The following code (below at end of post) will produce an example of the plot. However, for the pre-intervention period (period=1pre; left panel) I would like to constrain the x-axis to 1-10 and for the post-intervention period (right panel), constraint the x-axis from 10-20, in the 2-panel plot that is produced. As it is, the x-axis goes from 1-20 in both panels. I have tried a variety of things, including deleting the data rows that I don’t want out of the marginal effects object and then re-calling plot(me) - this constrains the data, but the x-axis is still 1-20 on both plots.
Is there any way to manually constrain the x-axis for this 2-panel marginal effects plot?
Thanks!
Code:
library(ggplot2)
library(brms)
pre_treat1<-rnorm(10,30,1)
post_treat1<-c(rnorm(3,25,1),rnorm(3,20,1),rnorm(4,15,1))
pre_control<-rnorm(10,30,1)
post_control<-rnorm(10,30,1)
pre_treat2<-rnorm(10,30,1)
post_treat2<-c(rnorm(3,28,1),rnorm(3,26,1),rnorm(4,25,1))
outcome<-c(pre_treat1,post_treat1,pre_control,post_control,pre_treat2,post_treat2)
time_treat1<-1:20
time_control<-1:20
time_treat2<-1:20
time<-c(time_treat1,time_control,time_treat2)
pre_period_treat1<-rep(“1pre”,10)
post_period_treat1<-rep(“2post”,10)
pre_period_control<-rep(“1pre”,10)
post_period_control<-rep(“2post”,10)
pre_period_treat2<-rep(“1pre”,10)
post_period_treat2<-rep(“2post”,10)
period<-c(pre_period_treat1,post_period_treat1,pre_period_control,post_period_control,pre_period_treat2,post_period_treat2)
treatment_treat1<-rep(“3treat1”,20)
treatment_control<-rep(“1control”,20)
treatment_treat2<-rep(“2treat2”,20)
treatment<-c(treatment_treat1,treatment_control,treatment_treat2)
data<-cbind(period,treatment)
data<-data.frame(data)
data$outcome<-outcome
data$time<-time
model.3way<-brm(outcome ~ treatmentperiodtime, data=data)
conditions <- make_conditions(model.3way, “period”)
me<-marginal_effects(model.3way, “time:treatment”, conditions = conditions)
plot(me)