title: Extracting x-axis intercept from a linear fit in R
body: <p>I have some data generated using the following lines of code,</p>
  
  <pre><code>x &lt;- c(1:10)
  y &lt;- x^3
  z &lt;- y-20
  s &lt;- z/3
  t &lt;- s*6
  q &lt;- s*y
  x1 &lt;- cbind(x,y,z,s,t,q)
  x1 &lt;- data.frame(x1)
  </code></pre>
  
  <p>I would like to plot x versus y,s, and t so I melt the data frame <code>x1</code> first,</p>
  
  <pre><code> library(reshape2)
  
   xm &lt;- melt(x1, id=names(x1)[1], measure=names(x1)[c(2, 4, 5)], variable = "cols"`)
  </code></pre>
  
  <p>Then I plot them along with their linear fits using the following code,</p>
  
  <pre><code>library(ggplot2)
  plt &lt;- ggplot(xm, aes(x = x, y = value, color = cols)) +
    geom_point(size = 3) +
    labs(x = "x", y = "y") + 
    geom_smooth(method = "lm", se = FALSE)
  plt
  </code></pre>
  
  <p>The plot which is generated is shown below,</p>
  
  <p><img src="https://i.stack.imgur.com/9EBI8.png" alt="enter image description here"></p>
  
  <p>Now I would liked to interpolate the <strong>x-intercept</strong> of the linear fit. The point in the plot where y axis value is 0.</p>
  
  <p>The following lines of code as shown <a href="https://stackoverflow.com/questions/21335625/getting-the-y-axis-intercept-and-slope-from-a-linear-regression-of-multiple-data">here</a>, extracts the slope and y-intercept.</p>
  
  <pre><code>fits &lt;- by(xm[-2], xm$cols, function(i) coef(lm(value ~ x, i)))
  data.frame(cols = names(fits), do.call(rbind, fits))
  </code></pre>
  
  <p>Is there any way how I can extract the x-intercept other than manually calculating from the slope and y-intercept?</p>
  
  <p>Thanks for the help!</p>