### Graf z matice X * Y x <- -10:10 y <- -10:10 z_values <- function(x, y) { sqrt(x ^ 2 + y ^ 2) } z = outer(x, y, z_values) persp(x, y, z) persp(x, y, z, xlab='X Variable', ylab='Y Variable', zlab='Z Variable', main='3D Plot', col='pink', shade=.4, theta = 30, phi = 15, ticktype='detailed') library(plot3D) persp3D(x,y,z,theta=30, phi=50, axes=TRUE,scale=2, box=TRUE, nticks=5, ticktype="detailed", xlab="x", ylab="y", zlab="z", main=" ") library(rgl) persp3d(x, y, z, col="skyblue") rgl.surface(x, y, z, color="orange", back="lines") library(plotly) plot_ly(x=x,y=y,z=z, type="surface") data(volcano) z <- 5 * volcano # Exaggerate the relief x <- 10 * (1:nrow(z)) # 10 meter spacing (S to N) y <- 10 * (1:ncol(z)) # 10 meter spacing (E to W) # par(bg = "white") persp(x, y, z, theta = 135, phi = 30, col = "brown", scale = FALSE, ltheta = -120, shade = 0.75, border = NA, box = FALSE) library(plot3D) persp3D(x,y,z,theta=30, phi=50, axes=FALSE,scale=1, box=FALSE, nticks=5, ticktype="detailed", xlab="X-value", ylab="Y-value", zlab="Z-value", main=" ") library(rgl) rgl.open() rgl.surface(x, y, z, color="orange", back="lines") library(plotly) plot_ly(x=x,y=y,z=z, type="surface") ### Graf z matice XYZ data(iris) head(iris) library(scatterplot3d) scatterplot3d(iris[,1:3]) scatterplot3d(iris[,1:3], angle = 55) scatterplot3d(iris[,1:3], main="3D Scatter Plot", xlab = "Sepal Length (cm)", ylab = "Sepal Width (cm)",zlab = "Petal Length (cm)", angle = 55, pch = 16, color="steelblue") shapes = c(16, 17, 18) shapes <- shapes[as.numeric(iris$Species)] scatterplot3d(iris[,1:3], pch = shapes) colors <- c("#999999", "#E69F00", "#56B4E9") colors <- colors[as.numeric(iris$Species)] scatterplot3d(iris[,1:3], pch = 16, color=colors) scatterplot3d(iris[,1:3], pch = 16, color = colors, grid=TRUE, box=FALSE) scatterplot3d(iris[,1:3], pch = 16, type="h", color=colors) s3d <- scatterplot3d(iris[,1:3], pch = 16, color=colors) legend(s3d$xyz.convert(7.5, 3, 4.5), legend = levels(iris$Species), col = c("#999999", "#E69F00", "#56B4E9"), pch = 16) s3d <- scatterplot3d(iris[,1:3], pch = 16, color=colors) legend("right", legend = levels(iris$Species), col = c("#999999", "#E69F00", "#56B4E9"), pch = 16) s3d <- scatterplot3d(iris[,1:3], pch = 16, color=colors) legend("right", legend = levels(iris$Species), col = c("#999999", "#E69F00", "#56B4E9"), pch = 16, inset = 0.1) s3d <- scatterplot3d(iris[,1:3], pch = 16, color=colors) legend("bottom", legend = levels(iris$Species), col = c("#999999", "#E69F00", "#56B4E9"), pch = 16) s3d <- scatterplot3d(iris[,1:3], pch = shapes) legend("bottom", legend = levels(iris$Species), pch = c(16, 17, 18), inset = -0.25, xpd = TRUE, horiz = TRUE) s3d <- scatterplot3d(iris[,1:3], pch = 16, color=colors) legend("bottom", legend = levels(iris$Species), col = c("#999999", "#E69F00", "#56B4E9"), pch = 16, inset = -0.6, xpd = TRUE, horiz = TRUE) scatterplot3d(iris[,1:3], pch = 16, color=colors) text(s3d$xyz.convert(iris[, 1:3]), labels = rownames(iris), cex= 0.7, col = "steelblue") data(trees) head(trees) s3d <- scatterplot3d(trees, type = "h", color = "blue", angle=55, pch = 16) my.lm <- lm(trees$Volume ~ trees$Girth + trees$Height) s3d$plane3d(my.lm) s3d$points3d(seq(10, 20, 2), seq(85, 60, -5), seq(60, 10, -10), col = "red", type = "h", pch = 8) x <- sep.l <- iris$Sepal.Length y <- pet.l <- iris$Petal.Length z <- sep.w <- iris$Sepal.Width scatter3D(x, y, z, clab = c("Sepal", "Width (cm)")) scatter3D(x, y, z, colvar = NULL, col = "blue", pch = 19, cex = 0.5) scatter3D(x, y, z, bty = "f", colkey = FALSE, main ="") scatter3D(x, y, z, bty = "b2", colkey = FALSE, main ="" ) scatter3D(x, y, z, bty = "g", colkey = FALSE, main ="") scatter3D(x, y, z, pch = 18, bty = "u", colkey = FALSE, main ="bty= 'u'", col.panel ="steelblue", expand =0.4, col.grid = "darkblue") scatter3D(x, y, z, bty = "g", pch = 18, col = gg.col(100)) # ggplot2 like scatter3D(x, y, z, bty = "g", pch = 18, col = ramp.col(c("blue", "yellow", "red")) ) scatter3D(x, y, z, bty = "g", pch = 18, col.var = as.integer(iris$Species), col = c("#1B9E77", "#D95F02", "#7570B3"), pch = 18, ticktype = "detailed", colkey = list(at = c(2, 3, 4), side = 1, addlines = TRUE, length = 0.5, width = 0.5, labels = c("setosa", "versicolor", "virginica")) ) scatter3D(x, y, z, bty = "g", colkey = list(side = 1, length = 0.5)) scatter3D(x, y, z, theta = 15, phi = 20) scatter3D(x, y, z, phi = 0, bty ="g") scatter3D(x, y, z, pch = 18, theta = 20, phi = 20, main = "Iris data", xlab = "Sepal.Length", ylab ="Petal.Length", zlab = "Sepal.Width") scatter3D(x, y, z, phi = 0, bty = "g", pch = 20, cex = 2, ticktype = "detailed") scatter3D(x, y, z, phi = 0, bty = "g", pch = 20, cex = 2, ticktype = "detailed") scatter3D(x = 7, y = 3, z = 3.5, add = TRUE, colkey = FALSE, pch = 18, cex = 3, col = "black") scatter3D(x, y, z, phi = 0, bty = "g", pch = 20, cex = 0.5) text3D(x, y, z, labels = rownames(iris), add = TRUE, colkey = FALSE, cex = 0.5) scatter3D(x, y, z, phi = 0, bty = "g", type = "l", ticktype = "detailed", lwd = 4) scatter3D(x, y, z, phi = 0, bty = "g", type = "b", ticktype = "detailed", pch = 20, cex = c(0.5, 1, 1.5)) scatter3D(x, y, z, phi = 0, bty = "g", type = "h", ticktype = "detailed", pch = 19, cex = 0.5) CI <- list(z = matrix(nrow = length(x), data = rep(0.1, 2*length(x)))) head(CI$z) scatter3D(x, y, z, phi = 0, bty = "g", col = gg.col(100), pch = 18, CI = CI) x <- sep.l <- iris$Sepal.Length y <- pet.l <- iris$Petal.Length z <- sep.w <- iris$Sepal.Width sp <- iris$Species library(lattice) cloud(z ~ x * y, xlab="X", ylab="Y", zlab="Z") cloud(z ~ x * y|sp, xlab="X", ylab="Y", zlab="Z") library(rgl) plot3d(x, y, z, type="p", size=3, lit=FALSE) library(plotly) plot_ly(as.data.frame(iris),x=~Sepal.Length, y=~Petal.Length, z=~Sepal.Width, color = ~Species) library(squash) data(volcano) head(volcano) volcano.xyz <- xyzmat2xyz(volcano) head(volcano.xyz) x <- -10:10 y <- -10:10 z_values <- function(x, y) { sqrt(x ^ 2 + y ^ 2) } z = outer(x, y, z_values) head(z) xyz.z <- xyzmat2xyz(z) head(xyz.z) xyz.m <- xyzmat.coords(x = x, y = y, z = z,xlab = NULL, ylab = NULL, zlab = NULL,xds = NULL, yds = NULL, zds = NULL) xyz.z <- xyzmat2xyz(xyz.m) head(xyz.z) xyz = as.data.frame(cbind(xyz.z$x,xyz.z$y,xyz.z$z)) names(xyz) = c("x","y","z")