#========================================== # Given a set of points (2d) plot the points # and connect to all neighbours. #========================================== connect.Map <- function(width, height, data, YL=c(0,1), XL=c(0,1), main="") { plot(data, pch=16, cex=1.5, xlim=XL, ylim=YL, main=main) # Right zig-zag for (i in 1:width) { lines(data[(1:height)+(i-1)*height, ]) } # Horizontal for (i in 0:(height- 1)) { lines(data[seq(1,(width*height), by=height) + i, ]) } # Left zig-zag for (i in 1:(width-1)) { lines(data[(1:height)+rep(c(height,0), (height+1)/2)[1:height]+(i-1)*height, ]) } } require(scatterplot3d) connect.3D <- function(width, height, data, Col=col, xlab=Xlab,ylab=Ylab,zlab=Zlab) { # s3d <- scatterplot3d(data, pch=16, color=Col, xlab="Red", ylab="Blue", zlab="Green") s3d <- scatterplot3d(data, pch=16, cex.symbols=2, color=Col, xlab=xlab, ylab=ylab, zlab=zlab) # Right zig-zag for (i in 1:width) { s3d$points3d(data[(1:height)+(i-1)*height, ],type="l",col="black") } # Horizontal for (i in 0:(height- 1)) { s3d$points3d(data[seq(1,(width*height), by=height) + i, ],type="l", col="black") } # Left zig-zag for (i in 1:(width-1)) { s3d$points3d(data[(1:height)+rep(c(height,0), (height+1)/2)[1:height]+(i-1)*height, ],type="l",col="black") } }