# How to plot linear, cubic and quadratic fitting curve in a figure?

6 messages
Open this post in threaded view
|
Report Content as Inappropriate

## How to plot linear, cubic and quadratic fitting curve in a figure?

Open this post in threaded view
|
Report Content as Inappropriate

## Re: How to plot linear, cubic and quadratic fitting curve in a figure?

Open this post in threaded view
|
Report Content as Inappropriate

## Re: How to plot linear, cubic and quadratic fitting curve in a figure?

 In reply to this post by Kristi Glover > dput(test) structure(list(sp = c(4L, 5L, 9L, 12L, 14L), env = c(12L, 18L, 20L, 17L, 15L)), .Names = c("sp", "env"), class = "data.frame", row.names = c(NA, -5L)) > plot(test\$sp~test\$env, main = "S vs. temp", xlim=c(0,20), ylim=c(0,14), > ylab="S",xlab="env") > linear<-lm(test\$sp~test\$env) > quadratic<-lm(test\$sp~test\$env+I(test\$env^2)) > #summary(quadratic) > cubic<-lm(test\$sp~test\$env+I(test\$env^2)+I(test\$env^3)) > #summary(cubic) > #fitting curve > abline(linear) > Thanks and waiting for your suggestions sincerely, Kristi Glover Try adding the following lines of code cq = coef(quadratic) cc = coef(cubic) newenv = seq(min(test\$env), max(test\$env), by = (max(test\$env) - min(test\$env))/500) sp.quad = cq[1] + cq[2]*newenv +cq[3]*newenv^2 lines(newenv,sp.quad, col='red') sp.cubic = cc[1] + cc[2]*newenv +cc[3]*newenv^2 +cc[4]*newenv^3 lines(newenv, sp.cubic, col='blue', lty=2) ------------------------------------------ Robert W. Baer, Ph.D. Professor of Physiology Kirksville College of Osteopathic Medicine A. T. Still University of Health Sciences 800 W. Jefferson St. Kirksville, MO 63501 660-626-2322 FAX 660-626-2965 ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: How to plot linear, cubic and quadratic fitting curve in a figure?

Open this post in threaded view
|
Report Content as Inappropriate

## Re: How to plot linear, cubic and quadratic fitting curve in a figure?

Open this post in threaded view
|
Report Content as Inappropriate