Sunday, April 7, 2013

RG#30: Level plot

require (lattice)
# data = volcano
levelplot(volcano)

#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)


# color brewing 
library("RColorBrewer"); library("lattice");
brewer.div <- colorRampPalette(brewer.pal(11, "Spectral"), interpolate = "spline")

#plot 
levelplot (zvar ~ xvar * yvar, data = gdr, cuts = 199, col.regions = brewer.div(200), aspect = "iso")



# ggplot2 version 
require(ggplot2)
pl<- ggplot(gdr, aes(xvar, yvar, z= zvar))
pl + geom_tile(aes(fill = zvar)) + theme_bw()



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.