2

I wonder if it is possible to show data values on levelplot (lattice package) in R. I'd appreciate if someone help me to do that. Thanks in advance.

plannapus
  • 18,529
  • 4
  • 72
  • 94
MYaseen208
  • 22,666
  • 37
  • 165
  • 309

1 Answers1

14

You can write your own panel function, e.g.:

library("lattice")
x <- seq(pi/4, 5*pi, length.out=10)
y <- seq(pi/4, 5*pi, length.out=10)
r <- as.vector(sqrt(outer(x^2, y^2, "+")))
grid <- expand.grid(x=x, y=y)
grid$z <- cos(r^2)*exp(-r/(pi^3))

p <- levelplot(z~x*y, grid, 
               panel=function(...) {
                       arg <- list(...)
                       panel.levelplot(...)
                       panel.text(arg$x, arg$y, round(arg$z,1))})
print(p)

panel.levelplot example

rcs
  • 67,191
  • 22
  • 172
  • 153
  • 2
    Check also similar plot on [lmdvr site](http://lmdvr.r-forge.r-project.org/figures/figures.html?chapter=13;figure=13_05;theme=stdColor;code=right). – Marek Jul 04 '11 at 16:16
  • In the above example, how can we change the default theme? – Vasilis Sep 29 '11 at 14:54
  • E.g. `levelplot(z~x*y, grid, col.regions = heat.colors(100))`. Also check this http://stackoverflow.com/questions/3712402/r-how-to-change-lattice-levelplot-color-theme – rcs Sep 29 '11 at 15:03