Research breakthrough possible @S-Logix

Office Address

  • 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
  • +91- 81240 01111

Social List

How to Visualize Regression Plane in R?


To visualize the regression plane using R programming.


   R Function :lm()

   To compute a linear regression model:ax + by + cz + d = 0

   Argument surf To add a regression surface.

  Surfis a list specifying a (fitted)surface to be added on the scatter plot.

   The list should include at least x,y, z, defining the surface.

Sapmle Code

#Regression Plane



#x, y, z variables





# Compute the linear regression (z = ax + by + d)

fit<-lm(z ~ x + y)


#Predict values on regular xy grid


x.pred<-seq(min(x), max(x), length.out = grid.lines)

y.pred<-seq(min(y), max(y), length.out = grid.lines)

xy<-expand.grid( x = x.pred, y = y.pred)

z.pred<-matrix(predict(fit, newdata = xy), nrow = grid.lines, ncol = grid.lines)


#Fitted points for droplines to surface



#Scatter plot with regression plane

scatter3D(x, y, z, pch = 18, cex = 2,

theta = 20, phi = 20, ticktype = “detailed”,

xlab = “wt”, ylab = “disp”, zlab = “mpg”,

surf = list(x = x.pred, y = y.pred, z = z.pred,

facets=NA,fit = fitpoints), main = “mtcars”)

Visualize Regression Plane in R