~ubuntu-branches/ubuntu/hardy/texmacs/hardy

« back to all changes in this revision

Viewing changes to plugins/r/r/TeXmacs/demo/T.persp.R

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Treinen
  • Date: 2004-04-19 20:34:00 UTC
  • Revision ID: james.westby@ubuntu.com-20040419203400-g4e34ih0315wcn8v
Tags: upstream-1.0.3-R2
ImportĀ upstreamĀ versionĀ 1.0.3-R2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
### Demos for  persp()  plots   -- things not in  example(persp)
 
2
### -------------------------
 
3
 
 
4
## is FALSE in demo() {using source()}:
 
5
## if(dev.interactive())
 
6
## Use a ``portable'' (;-) hack instead:
 
7
#is.dev.interactive <- eval(body(dev.interactive)[[3]])
 
8
#op <- par()
 
9
 
 
10
## (1) The Obligatory Mathematical surface.
 
11
##     Rotated sinc function.
 
12
 
 
13
x <- seq(-10, 10, length = 50)
 
14
y <- x
 
15
rotsinc <- function(x,y)
 
16
{
 
17
    sinc <- function(x) { y <- sin(x)/x ; y[is.na(y)] <- 1; y }
 
18
    10 * sinc( sqrt(x^2+y^2) )
 
19
}
 
20
sinc.exp <- expression(z == Sinc(sqrt(x^2 + y^2)))
 
21
 
 
22
z <- outer(x, y, rotsinc)
 
23
 
 
24
 
 
25
par(bg = "white")
 
26
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")
 
27
title(sub=".")## work around persp+plotmath bug
 
28
title(main = sinc.exp)
 
29
v()
 
30
 
 
31
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue",
 
32
      ltheta = 120, shade = 0.75, ticktype = "detailed",
 
33
      xlab = "X", ylab = "Y", zlab = "Z")
 
34
title(sub=".")## work around persp+plotmath bug
 
35
title(main = sinc.exp)
 
36
v()
 
37
 
 
38
 
 
39
## (2) Visualizing a simple DEM model
 
40
 
 
41
data(volcano)
 
42
z <- 2 * volcano        # Exaggerate the relief
 
43
x <- 10 * (1:nrow(z))   # 10 meter spacing (S to N)
 
44
y <- 10 * (1:ncol(z))   # 10 meter spacing (E to W)
 
45
persp(x, y, z, theta = 120, phi = 15, scale = FALSE, axes = FALSE)
 
46
v()
 
47
 
 
48
## (3) Now something more complex
 
49
##     We border the surface, to make it more "slice like"
 
50
##     and color the top and sides of the surface differently.
 
51
 
 
52
z0 <- min(z) - 20
 
53
z <- rbind(z0, cbind(z0, z, z0), z0)
 
54
x <- c(min(x) - 1e-10, x, max(x) + 1e-10)
 
55
y <- c(min(y) - 1e-10, y, max(y) + 1e-10)
 
56
 
 
57
fill <- matrix("green3", nr = nrow(z)-1, nc = ncol(z)-1)
 
58
fill[ , i2 <- c(1,ncol(fill))] <- "gray"
 
59
fill[i1 <- c(1,nrow(fill)) , ] <- "gray"
 
60
 
 
61
par(bg = "lightblue")
 
62
persp(x, y, z, theta = 120, phi = 15, col = fill, scale = FALSE, axes = FALSE)
 
63
title(main = "Maunga Whau\nOne of 50 Volcanoes in the Auckland Region.",
 
64
      font.main = 4)
 
65
v()
 
66
 
 
67
par(bg = "slategray")
 
68
persp(x, y, z, theta = 135, phi = 30, col = fill, scale = FALSE,
 
69
      ltheta = -120, lphi = 15, shade = 0.65, axes = FALSE)
 
70
v()
 
71
## Don't draw the grid lines :  border = NA
 
72
persp(x, y, z, theta = 135, phi = 30, col = "green3", scale = FALSE,
 
73
      ltheta = -120, shade = 0.75, border = NA, box = FALSE)
 
74
v()
 
75
## `color gradient in the soil' :
 
76
fcol <- fill ; fcol[] <- terrain.colors(nrow(fcol))
 
77
persp(x, y, z, theta = 135, phi = 30, col = fcol, scale = FALSE,
 
78
      ltheta = -120, shade = 0.3, border = NA, box = FALSE)
 
79
v()
 
80
## `image like' colors on top :
 
81
fcol <- fill
 
82
zi <- volcano[ -1,-1] + volcano[ -1,-61] +
 
83
           volcano[-87,-1] + volcano[-87,-61]  ## / 4
 
84
fcol[-i1,-i2] <-
 
85
    terrain.colors(20)[cut(zi, quantile(zi, seq(0,1, len = 21)),
 
86
                           include.lowest = TRUE)]
 
87
persp(x, y, 2*z, theta = 110, phi = 40, col = fcol, scale = FALSE,
 
88
      ltheta = -120, shade = 0.4, border = NA, box = FALSE)
 
89
 
 
90
v()
 
91
## reset par():
 
92
#par(op)