0

I have not been able to find anything useful (except loads of information about Excel) on how to create a 2nd order trendline in a scatter plot using R. I did read one post that was way over my head (https://stats.stackexchange.com/questions/71187/getting-a-second-order-polynomial-trend-line-from-a-set-of-data).

    A <- c(0, 5.4, 7.7, 9.4, 10.9, 12.2, 13.4, 14.5, 15.5, 16.4, 
17.3)
    B <- c(0, 0.12, 0.37, 0.49, 0.62, 0.87, 1.11, 1.3, 1.6, 1.8, 
2)
    df <- data.frame(A, B)
    ggplot(data = df) + geom_point(mapping = aes(x = A, y = B)) + 
labs(title = "H1") + theme(plot.title = element_text(hjust = 0.5))

This is what I want (used Excel - not with the same data).

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Binx
  • 382
  • 7
  • 22
  • 2
    Try referencing [this post](https://stackoverflow.com/questions/11949331/adding-a-3rd-order-polynomial-and-its-equation-to-a-ggplot-in-r). Although this question is concerned about the third order polynomial, you can simply substitute the _3_'s for _2_'s. – OTStats Jan 20 '19 at 01:17
  • do you get if you search for "quadratic fit" or "quadratic trend line"? – Ben Bolker Jan 20 '19 at 01:17
  • Sorry Ben Bolker, I am not fully understanding your question. – Binx Jan 20 '19 at 01:59
  • 1
    OTStats, I did look at this post earlier and it didn't work, however this time around I got it to work. I will post the code below for others to see. – Binx Jan 20 '19 at 02:00

0 Answers0