R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("scatterplot3d-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('scatterplot3d') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "scatterplot3d" > > ### * scatterplot3d > > flush(stderr()); flush(stdout()) > > ### Name: scatterplot3d > ### Title: 3D Scatter Plot > ### Aliases: scatterplot3d > ### Keywords: hplot > > ### ** Examples > > ## On some devices not all colors can be displayed. > ## Try the postscript device or use highlight.3d = FALSE. > > ## example 1 > z <- seq(-10, 10, 0.01) > x <- cos(z) > y <- sin(z) > scatterplot3d(x, y, z, highlight.3d=TRUE, col.axis="blue", + col.grid="lightblue", main="scatterplot3d - 1", pch=20) > > ## example 2 > temp <- seq(-pi, 0, length = 50) > x <- c(rep(1, 50) %*% t(cos(temp))) > y <- c(cos(temp) %*% t(sin(temp))) > z <- c(sin(temp) %*% t(sin(temp))) > scatterplot3d(x, y, z, highlight.3d=TRUE, + col.axis="blue", col.grid="lightblue", + main="scatterplot3d - 2", pch=20) > > ## example 3 > temp <- seq(-pi, 0, length = 50) > x <- c(rep(1, 50) %*% t(cos(temp))) > y <- c(cos(temp) %*% t(sin(temp))) > z <- 10 * c(sin(temp) %*% t(sin(temp))) > color <- rep("green", length(x)) > temp <- seq(-10, 10, 0.01) > x <- c(x, cos(temp)) > y <- c(y, sin(temp)) > z <- c(z, temp) > color <- c(color, rep("red", length(temp))) > scatterplot3d(x, y, z, color, pch=20, zlim=c(-2, 10), + main="scatterplot3d - 3") > > ## example 4 > my.mat <- matrix(runif(25), nrow=5) > dimnames(my.mat) <- list(LETTERS[1:5], letters[11:15]) > my.mat # the matrix we want to plot ... k l m n o A 0.2655087 0.89838968 0.2059746 0.4976992 0.9347052 B 0.3721239 0.94467527 0.1765568 0.7176185 0.2121425 C 0.5728534 0.66079779 0.6870228 0.9919061 0.6516738 D 0.9082078 0.62911404 0.3841037 0.3800352 0.1255551 E 0.2016819 0.06178627 0.7698414 0.7774452 0.2672207 > > s3d.dat <- data.frame(cols=as.vector(col(my.mat)), + rows=as.vector(row(my.mat)), + value=as.vector(my.mat)) > scatterplot3d(s3d.dat, type="h", lwd=5, pch=" ", + x.ticklabs=colnames(my.mat), y.ticklabs=rownames(my.mat), + color=grey(25:1/40), main="scatterplot3d - 4") > > ## example 5 > data(trees) > s3d <- scatterplot3d(trees, type="h", highlight.3d=TRUE, + angle=55, scale.y=0.7, pch=16, main="scatterplot3d - 5") > # Now adding some points to the "scatterplot3d" > s3d$points3d(seq(10,20,2), seq(85,60,-5), seq(60,10,-10), + col="blue", type="h", pch=16) > # Now adding a regression plane to the "scatterplot3d" > attach(trees) > my.lm <- lm(Volume ~ Girth + Height) > s3d$plane3d(my.lm, lty.box = "solid") > > ## example 6; by Martin Maechler > cubedraw <- function(res3d, min = 0, max = 255, cex = 2, text. = FALSE) + { + ## Purpose: Draw nice cube with corners + cube01 <- rbind(c(0,0,1), 0, c(1,0,0), c(1,1,0), 1, c(0,1,1), # < 6 outer + c(1,0,1), c(0,1,0)) # <- "inner": fore- & back-ground + cub <- min + (max-min)* cube01 + ## visibile corners + lines: + res3d$points3d(cub[c(1:6,1,7,3,7,5) ,], cex = cex, type = 'b', lty = 1) + ## hidden corner + lines + res3d$points3d(cub[c(2,8,4,8,6), ], cex = cex, type = 'b', lty = 3) + if(text.)## debug + text(res3d$xyz.convert(cub), labels=1:nrow(cub), col='tomato', cex=2) + } > ## 6 a) The named colors in R, i.e. colors() > cc <- colors() > crgb <- t(col2rgb(cc)) > par(xpd = TRUE) > rr <- scatterplot3d(crgb, color = cc, box = FALSE, angle = 24, + xlim = c(-50, 300), ylim = c(-50, 300), zlim = c(-50, 300)) > cubedraw(rr) > ## 6 b) The rainbow colors from rainbow(201) > rbc <- rainbow(201) > Rrb <- t(col2rgb(rbc)) > rR <- scatterplot3d(Rrb, color = rbc, box = FALSE, angle = 24, + xlim = c(-50, 300), ylim = c(-50, 300), zlim = c(-50, 300)) > cubedraw(rR) > rR$points3d(Rrb, col = rbc, pch = 16) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > ### *