title: how to define graphical bounds of abline linear regression in R
body: <p>I am trying to truncate the ends of an abline, which is actually just a linear regression of my data. </p>
  
  <pre><code>fit1=lm(logy~logx)
  
  &gt; fit1
  
  Call:
  lm(formula = logy ~ logx)
  
  Coefficients:
  (Intercept)         logx  
       -5.339       -2.115 
  </code></pre>
  
  <p>Where logx is <code>log10(x[1:365]</code> transformed. logy follows the same code. When I plot with <code>abline(fit1,col="red")</code>, I get the line I wanted, but the line extends past the bounds I have originally set <code>[1:365]</code>. I have tried <code>par=xpd</code> and that doesn't reduce the line to the limits I want. I've played around with <code>segments()</code> to no avail. Maybe it is a <code>line()</code> argument?</p>
  
  <p>edit
  Here is the new solution:</p>
  
  <pre><code>#the following vectors x and y store our data that we want to plot
  x&lt;-(1:10)
  y&lt;-(10:1)
  plot(x,y,type="l",log="xy")
  #we want to do a linear regression on our log10 transformed data and add the line to the plot
  logy=log10(y[3:8])
  logx=log10(x[3:8])
  fit1=lm(logy~logx)
  #finally, we want the regression line to only seem like it applies over the range from 3 to 8
  clip(3,8,8,3)
  abline(fit1,col="red")
  </code></pre>
  
  <p>what this yields is a plot with a line that (now, does not) extends past 3 to 8 on our x-axis. I only want the regression line to display from x=3 to x=8, following the same slope.</p>