Either latticeExtra::wireframe
or rgl::persp3d
can plot 3D surface plots.
z <- as.matrix(read.table(text='-4 -3 -2 -1 0 1 2 3 4
1 159 144 133 132 138 123 80 28 -22
2 153 135 121 122 160 162 110 50 -7
3 148 126 107 104 161 190 135 67 3
4 145 120 96 92 161 202 149 77 8
5 144 117 92 89 161 205 153 80 10
6 145 120 96 92 161 202 149 77 8
7 148 126 107 104 161 190 135 67 3
8 153 135 121 122 160 162 110 50 -7
9 159 144 133 132 138 123 80 28 -22', header=TRUE, check.names=FALSE))
First, with latticeExtra
:
library(latticeExtra)
wireframe(z, scales=list(arrows=FALSE), xlab='x', ylab='y', drape=TRUE,
col.regions=terrain.colors(10), at=seq(min(z), max(z), len=11))

See ?wireframe
for details on how to specify the viewing angle.
Alternatively, persp3d
from the rgl
package can generate 3D surfaces that can be rotated/zoomed with the mouse.
library(rgl)
persp3d(1:9, -4:4, z, col = "lightblue", xlab='x', ylab='y')
You could also consider a heatmap/levelplot for this:
lattice::levelplot(z, col.regions=terrain.colors, xlab='x', ylab='y',
scales=list(tck=1:0))

EDIT
You can use akima
to interpolate your data if you want to increase the resolution of the plots.
For example:
library(akima)
xyz <- transform(expand.grid(x=as.numeric(rownames(z)),
y=as.numeric(colnames(z))), z=c(z))
z_interp <- interp(xyz$x, xyz$y, xyz$z)
xyz_interp <- transform(expand.grid(x=z_interp$x, y=z_interp$y), z=c(z_interp$z))
wireframe(z ~ x * y, data=xyz_interp, scales=list(arrows=FALSE),
drape=TRUE, col.regions=terrain.colors(10),
at=seq(min(xyz_interp$z), max(xyz_interp$z), len=11))

Control the interpolated resolution with arguments xo
and yo
to interp
.