top of page

#Librerías necesarias

install.packages("rgl")

install.packages("plot3Drgl")

install.packages("magick")

library("magick")

library("rgl")

library("plot3Drgl")

#Codigo

require(plot3D)

require(plot3Drgl)

attach(mtcars)

# linear fit
fit <- lm(mpg ~ wt+disp)

# predict on x-y grid, for surface
wt.pred <- seq(1.5, 5.5, length.out = 30)
disp.pred <- seq(71, 472, length.out = 30)
xy <- expand.grid(wt = wt.pred, 
                  disp = disp.pred)

mpg.pred <- matrix (nrow = 30, ncol = 30, 
                    data = predict(fit, newdata = data.frame(xy), interval = "prediction"))

# predicted z-values, fitted points for droplines to surface
fitpoints <- predict(fit) 

scatter3D(z = mpg, x = wt, y = disp, pch = 18, cex = 2, 
          theta = 20, phi = 20, ticktype = "detailed",
          xlab = "PESO", ylab = "CILINDRADA", zlab = "km/l", clab = "km/l", 
          surf = list(x = wt.pred, y = disp.pred, z = mpg.pred, 
                      facets = NA, fit = fitpoints),
          colkey = list(length = 0.8, width = 0.4),            
          main = "Consumo Combustible")
plotrgl (lighting = TRUE, smooth = FALSE)

#Giro Automatico

play3d( spin3d( axis = c(0, 0, 1), rpm = 7), duration = 100 )

# O Generar Gif

movie3d( spin3d( axis = c(0, 0, 1), rpm = 7),
         duration = 10, dir = getwd(),
         type = "gif", clean =  TRUE )

###################################################

install.packages("rgl")

install.packages("plot3Drgl")

install.packages("magick")

library("magick")

library("rgl")

library("plot3Drgl")

require(plot3D)

require(plot3Drgl)​

attach(mtcars)

# linear fit
fit <- lm(mpg ~ wt+disp)

# predict on x-y grid, for surface
wt.pred <- seq(1.5, 5.5, length.out = 30)
disp.pred <- seq(71, 472, length.out = 30)
xy <- expand.grid(wt = wt.pred, 
                  disp = disp.pred)

mpg.pred <- matrix (nrow = 30, ncol = 30, 
                    data = predict(fit, newdata = data.frame(xy), interval = "prediction"))

# predicted z-values, fitted points for droplines to surface
fitpoints <- predict(fit) 

scatter3D(z = mpg, x = wt, y = disp, pch = 18, cex = 2, 
          theta = 20, phi = 20, ticktype = "detailed",
          xlab = "PESO", ylab = "CILINDRADA", zlab = "km/l", clab = "km/l", 
          surf = list(x = wt.pred, y = disp.pred, z = mpg.pred, 
                      facets = NA, fit = fitpoints),
          colkey = list(length = 0.8, width = 0.4),            
          main = "Consumo Combustible")
plotrgl (lighting = TRUE, smooth = FALSE)


plotrgl (lighting = TRUE, smooth = FALSE)

play3d( spin3d( axis = c(0, 0, 1), rpm = 7), duration = 100 );

###################################################

”Bien! Mensaje recibido

  • b-facebook
  • Twitter Round
bottom of page