0

I have used ggplot to the below dataframe(cars dataset) for 2 categories. I need to have 2 regression equations for 2 categories. Below is the code I have executed to plot the graph

 cars$cat <- ifelse(cars$speed>10,"greater than 10","less than 10")
ggplot(cars,aes(x=dist,y=speed,color=cat))+geom_point()+geom_smooth(method = lm)

Can you help me in putting the 2 regression equations

Rfer R
  • 69
  • 5
  • Your codes are already generating two lines on the graph. I don't understand the point. – maydin Aug 04 '19 at 10:09
  • If I understand you correctly you want to add regression equations not regression lines. Take a look at https://stackoverflow.com/a/35140066/3184024 – wici Aug 04 '19 at 10:42
  • @ Maydin, I need to add regression equation near the plot. – Rfer R Aug 04 '19 at 13:20
  • @wici, thanks. I did see that, Is there not a easier way than that? – Rfer R Aug 04 '19 at 13:27
  • @RferR So please change the title of the question, because it is *"Is there a R function to add Regression **line** to ggplot"*. – maydin Aug 04 '19 at 13:46
  • Possible duplicate of [Adding a regression line on a ggplot](https://stackoverflow.com/questions/15633714/adding-a-regression-line-on-a-ggplot) – Grada Gukovic Aug 04 '19 at 20:50
  • @Grada, thanks, But I need to add regression equation as well – Rfer R Aug 05 '19 at 04:51

0 Answers0