Skip to content
Prev 343372 / 398506 Next

Filled vector contours

On Aug 24, 2014, at 1:30 PM, Jan Tosovsky wrote:

            
Most people with any R experience would have thought that "levelplot" referred to something like:
(Example 6.9 from Lattice, by Deepayan Sarkar to which I have only added the contour line parameter which it appears is what you were seeking.)

env <- environmental 
env$ozone <- env$ozone^(1/3) 
env$Radiation <- equal.count(env$radiation, 4)
fm1.env <- lm(ozone ~ radiation * temperature * wind, env) 
fm2.env <- loess(ozone ~ wind * temperature * radiation, env, span = 0.75, degree = 1) 
fm3.env <- loess(ozone ~ wind * temperature * radiation, env, parametric = c("radiation", "wind"), span = 0.75, degree = 2) 
library("locfit") ; library(lattice)
fm4.env <- locfit(ozone ~ wind * temperature * radiation, env) 
w.mesh <- with(env, do.breaks(range(wind), 50)) 
t.mesh <- with(env, do.breaks(range(temperature), 50)) 
r.mesh <- with(env, do.breaks(range(radiation), 3)) 
grid <- expand.grid(wind = w.mesh, temperature = t.mesh, radiation = r.mesh) 
grid[["fit.linear"]] <- predict(fm1.env, newdata = grid) 
grid[["fit.loess.1"]] <- as.vector(predict(fm2.env, newdata = grid)) 
grid[["fit.loess.2"]] <- as.vector(predict(fm3.env, newdata = grid)) 
grid[["fit.locfit"]] <- predict(fm4.env, newdata = grid)

png()
print(levelplot(fit.linear + fit.loess.1 + fit.loess.2 + fit.locfit ~ wind * temperature | radiation, data = grid, contour=TRUE))
dev.off()