[R] plot with a regression line(s)

Sam Steingold sds at gnu.org
Wed Apr 4 17:13:04 CEST 2012


I am sure a common need is to plot a scatterplot with some fitted
line(s) and maybe save to a file.
I have this:

plot.glm <- function (x, y, file = NULL, xlab = deparse(substitute(x)),
                      ylab = deparse(substitute(y)), main = NULL) {
  m <- glm(y ~ x)
  if (!is.null(file))
    pdf(file = file)
  plot(x, y, xlab = xlab, ylab = ylab, main = main)
  lines(x, y = m$fitted.values, col = "green")
  if (!is.null(file))
    dev.off()
  print(m)
}

is there a better/easier/more general way?

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://truepeace.org http://openvotingconsortium.org
http://jihadwatch.org http://iris.org.il http://honestreporting.com
Even Windows doesn't suck, when you use Common Lisp



More information about the R-help mailing list