Home > Back-end >  Adding a Curve to a plot
Adding a Curve to a plot

Time:11-05

I want to add a random curve to a plot to test whats fitting best to my data.

df <- data.frame(a = c(-1.973, -1.685, 2.050, 0.496, 3.310, 2.604, 1.477, 5.552, 2.039, 1.503, 2.171, 1.095),
                 b = c(21,27,36,36,66,53,40,40,65,39,37,32))
lm(b~a,data = df)plot(df$a, df$b, xlab = "a", ylab = "b")
x<-lm(df$b~df$a)$coefficients[1]
curve(x lm(df$b~df$a)$coefficients[2], add=TRUE, col="red")

Though this plot I can draw a regression line (picture) but can I also add a random curve? enter image description here Or if you really wanted to use curve(), the x variable is special and needs to be able to change. So it would be

curve(reg$coefficients[1]   x*reg$coefficients[2], add=TRUE, col="red")
  • Related