title: Understanding Data Characteristics for Linear Regression in R - Plotting Data Distribution Over the Regression Line
body: <p>I am trying to understand how I might understand some properties of data when working through regression problems. Specifically, I would like to see the distribution of the data (y) characterized as a normal distribution at a given value of the regressor (x), and then plot this normal distribution (rotated 90 degrees) with the data and the regression line.</p>
  <p>This is what I'm working with to try to figure things out (this code works fine):</p>
  <pre><code>library(BAS)  # for data
  x &lt;- bodyfat$Abdomen
  y &lt;- bodyfat$Bodyfat
  dat &lt;- data.frame(cbind(x, y))
  
  # Linear model
  fat.mod &lt;- lm(y ~ x, data = dat)
  
  # Plot of linear model and data
  g &lt;- ggplot(bodyfat, aes(x = Abdomen, y = Bodyfat)) + geom_point() + 
    geom_smooth(method = &quot;lm&quot;, se = FALSE)
  g
  </code></pre>
  <p>What I would like to see is an image like this: <a href="https://i.stack.imgur.com/5V7Sn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5V7Sn.png" alt="this example" /></a>, but for x values that I could specify (maybe with some spread in x?). With the plot, I would like to see the characteristics of the overlaid distribution (mean and standard deviation or variance). Making the assumption that the data is normally distributed about the regression line is OK.</p>
  <p>Where I really fall apart is if I specify a point that is not explicitly in the data (e.g., the mean).</p>
  <p>Any thoughts on this?</p>
  <p>Many thanks!</p>