1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| x <-seq(-10, 10, length=30) y <- x f <-function(x, y){ r <-sqrt(x^2+y^2); 10*sin(r)/r } z <-outer(x, y, f) z[is.na(z)]<-1 op <-par(bg ="white", mar=c(1,1,1,1))
col.table1 <- topo.colors(400) col.table2 <- heat.colors(400) col.table3 <- terrain.colors(400) col.table4 <- cm.colors(400)
ncz <-ncol(z) nrz <-nrow(z)
zfacet <- z[-1, -1]+z[-1, -ncz]+z[-nrz, -1]+ z[-nrz, -ncz]
col.ind <- as.numeric(cut(zfacet, 400))
par(mfrow =c(2,2), mar = c(1, 1, 1, 1))
persp(x, y, z, theta =30, phi =30, expand =0.5, col= col.table1[col.ind], main ="topo.colors") persp(x, y, z, theta =30, phi =30, expand =0.5, col= col.table2[col.ind], main ="heat.colors") persp(x, y, z, theta =30, phi =30, expand =0.5, col= col.table3[col.ind], main ="terrain.colors") persp(x, y, z, theta =30, phi =30, expand =0.5, col= col.table4[col.ind], main ="cm.colors") 注: lattice程序包的wireframe函数提供了颜色的渲染方法。 wireframe(volcano, drape =TRUE, aspect =c(61/87, 0.4)) wireframe(volcano, shade =TRUE, aspect =c(61/87, 0.4)) wireframe(z, shade =TRUE, aspect =c(61/87, 0.4)) wireframe(z, drape =TRUE, aspect =c(61/87, 0.4))
|