R has many different related tools. In particular, look at the spatial view . A similar question was asked in R-Help before, so you can look at it .
Take a look at the contour functions. Here are some details:
x <- seq(-3,3) y <- seq(-3,3) z <- outer(x,y, function(x,y,...) x^2 + y^2 )
The initial schedule is somewhat rough:
contour(x,y,z, lty=1)
Bill Dunlap suggested an improvement: “It often works better to fit a smooth surface to data, evaluate that surface on a finer grid and pass the result to the path. This ensures that the path lines do not intersect and tends to avoid false loops that you could get by smoothing the contour lines themselves. Thin plate splines (Tps from the library ("fields")) and loess (among others) can match the surface. "
library("fields") contour(predict.surface(Tps(as.matrix(expand.grid(x=x,y=y)),as.vector(z))))
This leads to a very smooth graph because it uses Tps() to pick data first and then calls contour . It looks like this (you can also use fill.contour if you want it to be shaded):

For the graph, you can use either lattice (as in the above example), or in the ggplot2 package. Use the geom_contour() function in this case. An example can be found here (ht Thierry) :
ds <- matrix(rnorm(100), nrow = 10) library(reshape) molten <- melt(data = ds) library(ggplot2) ggplot(molten, aes(x = X1, y = X2, z = value)) + geom_contour()
Shane
source share