title: R: create generic plot in ggplot2
body: <p>Trying to create a line chart representing a simple slopes analysis. I created the plot using the builtin plot() command. How would I rewrite this code for ggplot2? I tried in ggplot2 but couldn't achieve this figure so I wrote using plot(). </p>
  
  <p>Here is the code I used to create my plot.</p>
  
  <pre><code>yrange = c(4,7)
  xrange = c(-1.5,1.5)
  par(bty = 'l')
  par(family="Times")
  plot(c(-1, 1), c(5.8, 6.2), type='b', lty=1, pch = 15, axes=F, xlab="", ylab="", ylim=yrange, xlim=xrange)
  par(new = T)
  plot(c(-1, 1), c(5.3, 5.5), type='b', lty=2, pch = 17, axes=F, xlab="IV1", ylab="DV", ylim=yrange, xlim=xrange)
  axis(1, at=c(-1,1), labels=c("Cond1", "Cond2"))
  axis(2, at=c(4, 5,6,7))
  legend("topright", title = "Moderator", c("High", "Low"), lty=1:2)
  box()
  </code></pre>
  
  <p>Here is the code I used while trying to create the above figure using ggplot2.  I couldn't fiture out how to create the legend for the moderator, how to change the x-axis labels, add boxes/triangles/circles to the end of the lines, or otherwise the set the lines to look like a proper publication quality APA figure::</p>
  
  <pre><code>ggplot(df) +
    geom_segment(aes(x = -1, y = 5.8, xend = +1, yend = 6.2), linetype = 1) + 
    geom_segment(aes(x = -1, y = 5.3, xend = +1, yend = 5.5), linetype = 2) + 
    labs(x = 'IV1', y = 'DV') +
    coord_cartesian(ylim = c(4, 7)) +  
    scale_x_continuous(breaks=seq(-1, +1, 2)) +  
    theme(legend.position = "bottom")
  </code></pre>
  
  <p>And, sorry, but this is my first post here. I am interested in using ggplot2 more but it's got a steep learning curve, even for R. </p>
  
  <hr>
  
  <p>@Pdubbs - I updated your code to make it closer to my situation. As I noted below, I'm trying to plot a 2x2 interactions between two continuous variables and the figure I'm creating is to visualize the interaction using a simple slopes regression analysis. Here is what happens and the output when I run this code:</p>
  
  <pre><code>&gt; df&lt;-data.frame(DV = c(5.8,5.3,6.2,5.5), 
  +                Moderator = c(1,2,3,4), 
  +                IV1 = c(6,4,3,2))
  &gt; 
  &gt; ggplot(df,aes(x=IV1,y=DV,shape=Moderator)) + geom_point() +
  +   geom_segment(aes(x = 1, y = 5.8, xend = 2, yend = 6.2), linetype = 1) + 
  +   geom_segment(aes(x = 1, y = 5.3, xend = 2, yend = 5.5), linetype = 2) + 
  +   labs(x = 'IV1', y = 'DV') +
  +   coord_cartesian(ylim = c(4, 7)) +  
  +   theme(legend.position = "bottom")
  Error: A continuous variable can not be mapped to shape
  </code></pre>
  
  <hr>
  
  <p>A couple last changes I can't figure out. How to increase the size the endpoints of the lines? For instance, make the triangles larger?</p>
  
  <p>A couple other issues with the legend. First, how to put a black box around the legend? Not a black background, just a simple black box outline around the legend. Second, how to add a solid or dashed line to the legend in addition to the circle or triangle? Third, how to center the legend title text? See the generic plot code as an example of what I mean all 3 of these. </p>