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("misc3d-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('misc3d') Loading required package: rgl > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "contour3d" > > ### * contour3d > > flush(stderr()); flush(stdout()) RGL: NO WM_DELETE > > ### Name: contour3d > ### Title: Draw an Isosurface, a Three Dimension Contour Plot > ### Aliases: contour3d > ### Keywords: hplot > > ### ** Examples > > #Example 1: Draw a ball > f <- function(x, y, z)x^2+y^2+z^2 > x <- seq(-2,2,len=20) > contour3d(f,4,x,x,x) > > #Example 2: Nested contours of mixture of three tri-variate normal densities > nmix3 <- function(x, y, z, m, s) { + 0.4 * dnorm(x, m, s) * dnorm(y, m, s) * dnorm(z, m, s) + + 0.3 * dnorm(x, -m, s) * dnorm(y, -m, s) * dnorm(z, -m, s) + + 0.3 * dnorm(x, m, s) * dnorm(y, -1.5 * m, s) * dnorm(z, m, s) + } > f <- function(x,y,z) nmix3(x,y,z,.5,.5) > g <- function(n = 40, k = 5, alo = 0.1, ahi = 0.5, cmap = heat.colors) { + th <- seq(0.05, 0.2, len = k) + col <- rev(cmap(length(th))) + al <- seq(alo, ahi, len = length(th)) + x <- seq(-2, 2, len=n) + for (i in seq(along = th)) { + contour3d(f,th[i],x,x,x,color=col[i],alpha=al[i], + add = (i != 1)) + } + rgl.bg(col="white") + } > g(40,5) > > ## Not run: > ##D #Example 3: Nested contours for FMRI data. > ##D library(AnalyzeFMRI) > ##D a<-f.read.analyze.volume(system.file("example.img", package="AnalyzeFMRI")) > ##D contour3d(aperm(a[,,,1],c(1,3,2)),1:64,1.5*(1:21),1:64,lev=3000,alpha=0.5) > ##D contour3d(aperm(a[,,,1],c(1,3,2)),1:64,1.5*(1:21),1:64,lev=8000, > ##D col="red",add=TRUE, alpha=0.5) > ##D contour3d(aperm(a[,,,1],c(1,3,2)),1:64,1.5*(1:21),1:64,lev=10000, > ##D col="green",add=TRUE) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "image3d" > > ### * image3d > > flush(stderr()); flush(stdout()) RGL: Pixmap load: file format unsupported RGL: Pixmap load: failed RGL: Pixmap load: file format unsupported RGL: Pixmap load: failed > > ### Name: image3d > ### Title: Draw Points on a 3D Grid > ### Aliases: image3d > ### Keywords: hplot > > ### ** Examples > > # view density of mixture of tri-variate normals > nmix3 <- function(x, y, z, m, s) { + 0.4 * dnorm(x, m, s) * dnorm(y, m, s) * dnorm(z, m, s) + + 0.3 * dnorm(x, -m, s) * dnorm(y, -m, s) * dnorm(z, -m, s) + + 0.3 * dnorm(x, m, s) * dnorm(y, -1.5 * m, s) * dnorm(z, m, s) + } > f <- function(x,y,z) nmix3(x,y,z,.5,.5) > x<-seq(-2,2,len=50) > g <- expand.grid(x = x, y = x, z = x) > v <- array(f(g$x, g$y, g$z), c(length(x), length(x), length(x))) > image3d(v) > image3d(v, jitter = TRUE) > > > > cleanEx(); ..nameEx <- "lines3d" > > ### * lines3d > > flush(stderr()); flush(stdout()) > > ### Name: lines3d > ### Title: Draw 3D Lines > ### Aliases: lines3d > ### Keywords: hplot > > ### ** Examples > > #Plot a three-dimensional helix. > t = seq(0,10*pi,by=pi/50) > lines3d(4*sin(t),4*cos(t),t,color="red") > > > > cleanEx(); ..nameEx <- "parametric3d" > > ### * parametric3d > > flush(stderr()); flush(stdout()) > > ### Name: parametric3d > ### Title: Draw a 3D Parametric Plot > ### Aliases: parametric3d > ### Keywords: hplot > > ### ** Examples > > #Example 1: Ratio-of-Uniform sampling region of bivariate normal > parametric3d(fx = function(u, v) u * exp(-0.5 * (u^2 + v^2 - + 2 * 0.75 * u * v)/sqrt(1-.75^2))^(1/3), + fy = function(u, v) v * exp(-0.5 * (u^2 + v^2 - + 2 * 0.75 * u * v)/sqrt(1-.75^2))^(1/3), + fz = function(u, v) exp(-0.5 * (u^2 + v^2 - 2 * 0.75 * u * + v)/sqrt(1-.75^2))^(1/3), + umin = -20, umax = 20, vmin = -20, vmax = 20, + n = 100) > > #Example 2: Ratio-of-Uniform sampling region of Bivariate t > parametric3d(fx = function(u,v) u*(dt(u,2) * dt(v,2))^(1/3), + fy = function(u,v) v*(dt(u,2) * dt(v,2))^(1/3), + fz = function(u,v) (dt(u,2) * dt(v,2))^(1/3), + umin = -20, umax = 20, vmin = -20, vmax = 20, + n = 100, color = "green", alpha=1.0) > > #Example 3: Surface of revolution > parametric3d(fx = function(u,v) u, + fy = function(u,v) sin(v)*(u^3+2*u^2-2*u+2)/5, + fz = function(u,v) cos(v)*(u^3+2*u^2-2*u+2)/5, + umin = -2.3, umax = 1.3, vmin = 0, vmax = 2*pi) > > > > > cleanEx(); ..nameEx <- "slices3d" > > ### * slices3d > > flush(stderr()); flush(stdout()) > > ### Name: slices3d > ### Title: Interactive Image Slices of 3D or 4D Volume Data > ### Aliases: slices3d > ### Keywords: hplot > > ### ** Examples > > #Example 1: View of a mixture of three tri-variate normal densities > nmix3 <- function(x, y, z, m, s) { + 0.4 * dnorm(x, m, s) * dnorm(y, m, s) * dnorm(z, m, s) + + 0.3 * dnorm(x, -m, s) * dnorm(y, -m, s) * dnorm(z, -m, s) + + 0.3 * dnorm(x, m, s) * dnorm(y, -1.5 * m, s) * dnorm(z, m, s) + } > x<-seq(-2, 2, len=40) > g<-expand.grid(x = x, y = x, z = x) > v<-array(nmix3(g$x,g$y,g$z, .5,.5), c(40,40,40)) > slices3d(v,col=heat.colors(256)) Loading required package: tkrplot Loading required package: tcltk Loading Tcl/Tk interface ... done > > ## Not run: > ##D #Example 2: View of FMRI data. > ##D library(AnalyzeFMRI) > ##D a<-f.read.analyze.volume(system.file("example.img", package="AnalyzeFMRI")) > ##D slices3d(aperm(a)) > ##D > ## End(Not run) > > > > ### *