#data
xvr <- seq(-5, 5, len = 50)
yvr <- seq(-5, 5, len = 50)
gdr <- expand.grid(xvar = xvr, yvar = yvr)
gdr$zvar <- rnorm (nrow(gdr), 4, 1)
#plot
require(lattice)
contourplot(zvar ~ xvar * yvar, data = gdr, cuts = 10)
#ggplot2 version
require(ggplot2)
plt <- ggplot(gdr, aes(xvar, yvar, z= zvar))
plt + stat_contour() + theme_bw()
# filled with zvar
plt + geom_tile(aes(fill = zvar)) + stat_contour() + theme_bw()
plt + stat_contour(geom="polygon", aes(fill=..level..)) + theme_bw()
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.