Last data update: 2014.03.03

R: Perspective plot with colour levels
persp3DR Documentation

Perspective plot with colour levels

Description

This function draws a perspective plot of a surface with different levels in different colors.

Usage

persp3D(x, y, z, theta = 30, phi = 20, d = 5, expand = 2/3,
        xlim = range(x, finite = TRUE), ylim = range(y, finite = TRUE), 
        zlim = range(z, finite = TRUE), levels = pretty(zlim, nlevels),
        nlevels = 20, color.palette = jet.colors, border = NA, 
        ticktype = "detailed", xlab = NULL, ylab = NULL, zlab = NULL, 
        ...)

Arguments

x, y

locations of grid lines at which the values in z are measured. These must be in ascending order. By default, equally spaced values from 0 to 1 are used. If x is a list, its components x$x and x$y are used for x and y, respectively.

z

a matrix containing the values to be plotted (NAs are allowed).

theta, phi

angles defining the viewing direction. theta gives the azimuthal direction and phi the colatitude.

d

a value which can be used to vary the strength of the perspective transformation.

expand

a expansion factor applied to the z coordinates.

xlim, ylim, zlim

x-, y- and z-limits for the axes.

levels

a vector of values specifying the levels to be used for plotting the surface with different colors.

nlevels

a value specifying the numbe of levels to be used for plotting. This value is used if levels argument is not specified.

color.palette

the color palette used for plotting.

border

the color of the line drawn around the surface facets. By default is set to NA so no borders are drawn.

ticktype

a character specifying the type of axes tickmarks. By default "detailed" ticks are drawn.

xlab, ylab, zlab

character strings specifying the titles for the axes.

...

Further arguments passed to the function persp.

Details

This function enhances the default perspective plot for drawing 3-dimensional surfaces.

Value

Return a list with the following elements:

persp

the viewing transformation matrix (see link{persp});

levels

a vector of values giving the levels used for plotting the surface;

colors

a vector of strings giving the color used for plotting the surface.

Author(s)

Luca Scrucca

See Also

link{persp}

Examples

y <- x <- seq(-10, 10, length=60)
f <- function(x,y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }
z <- outer(x, y, f)
persp3D(x, y, z, theta = 30, phi = 30, expand = 0.5)
persp3D(x, y, z, color.palette = heat.colors, phi = 30, theta = 225, 
        box = TRUE, border = NA, shade = .4)

x1 = seq(-3,3,length=50)
x2 = seq(-3,3,length=50)
y = function(x1, x2) sin(x1)+cos(x2)
persp3D(x1, x2, outer(x1,x2,y), zlab="y", theta = 150, phi = 20, expand = 0.6)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

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 an HTML browser interface to help.
Type 'q()' to quit R.

> library(GA)
Loading required package: foreach
Loading required package: iterators
Package 'GA' version 3.0.2
Type 'citation("GA")' for citing this R package in publications.
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GA/persp3D.Rd_%03d_medium.png", width=480, height=480)
> ### Name: persp3D
> ### Title: Perspective plot with colour levels
> ### Aliases: persp3D
> ### Keywords: hplot
> 
> ### ** Examples
> 
> y <- x <- seq(-10, 10, length=60)
> f <- function(x,y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }
> z <- outer(x, y, f)
> persp3D(x, y, z, theta = 30, phi = 30, expand = 0.5)
> persp3D(x, y, z, color.palette = heat.colors, phi = 30, theta = 225, 
+         box = TRUE, border = NA, shade = .4)
> 
> x1 = seq(-3,3,length=50)
> x2 = seq(-3,3,length=50)
> y = function(x1, x2) sin(x1)+cos(x2)
> persp3D(x1, x2, outer(x1,x2,y), zlab="y", theta = 150, phi = 20, expand = 0.6)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>