title: Visualising a three way interaction between two continuous variables and one categorical variable in R
body: <p>I have a model in R that includes a significant three-way interaction between two continuous independent variables IVContinuousA, IVContinuousB, IVCategorical and one categorical variable (with two levels: Control and Treatment). The dependent variable is continuous (DV).</p>
  
  <pre><code>model &lt;- lm(DV ~ IVContinuousA * IVContinuousB * IVCategorical)
  </code></pre>
  
  <p>You can find the data <a href="https://docs.google.com/spreadsheets/d/1avkYfeIXGxMy1F0YafiOYLQXEhzOWFKLXrk_y1EEb34/edit#gid=0" rel="noreferrer">here</a></p>
  
  <p>I am trying to find out a way to visualise this in R to ease my interpretation of it (perhaps in <code>ggplot2</code>?).</p>
  
  <p>Somewhat inspired by <a href="https://tomhouslay.com/2014/03/21/understanding-3-way-interactions-between-continuous-variables/" rel="noreferrer">this blog post</a> I thought that I could dichotomise <code>IVContinuousB</code> into high and low values (so it would be a two-level factor itself: </p>
  
  <pre><code>IVContinuousBHigh &lt;- mean(IVContinuousB) + sd (IVContinuousB) 
  IVContinuousBLow &lt;- mean(IVContinuousB) - sd (IVContinuousB)
  </code></pre>
  
  <p>I then planned to plot the relationship between DV and IV ContinuousA and fit lines representing the slopes of this relationship for different combinations of IVCategorical and my new dichotomised IVContinuousB:</p>
  
  <p><code>IVCategoricalControl</code> and <code>IVContinuousBHigh</code><br>
  <code>IVCategoricalControl</code> and <code>IVContinuousBLow</code><br>
  <code>IVCategoricalTreatment</code> and <code>IVContinuousBHigh</code><br>
  <code>IVCategoricalTreatment</code> and <code>IVContinuousBLow</code>  </p>
  
  <p>My first question is does this sound like a viable solution to producing an interpretable plot of this three-way-interaction? I want to avoid 3D plots if possible as I don't find them intuitive...  Or is there another way to go about it?  Maybe facet plots for the different combinations above?</p>
  
  <p>If it is an ok solution, my second question is how to I generate the data to predict the fit lines to represent the different combinations above?</p>
  
  <p>Third question - does anyone have any advice as to how to code this up in ggplot2?</p>
  
  <p>I posted a very similar question on Cross Validated but because it is more code related I thought I would try here instead (I will remove the CV post if this one is more relevant to the community :) )</p>
  
  <p>Thanks so much in advance,</p>
  
  <p>Sarah</p>
  
  <p>Note that there are <code>NA</code>s (left as blanks) in the DV column and the design is unbalanced - with slightly different numbers of datapoints in the Control vs Treatment groups of the variable IVCategorical.</p>
  
  <p>FYI I have the code for visaualising a two-way interaction between IVContinuousA and IVCategorical:</p>
  
  <p>A&lt;-ggplot(data=data,aes(x=AOTAverage,y=SciconC,group=MisinfoCondition,shape=MisinfoCondition,col = MisinfoCondition,))+geom_point(size = 2)+geom_smooth(method='lm',formula=y~x)</p>
  
  <p>But what I want is to plot this relationship conditional on IVContinuousB....</p>