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.
Asked
Active
Viewed 5,245 times
2
-
You mean to have a value for each cell? – Roman Luštrik Jul 04 '11 at 09:44
-
Yes. I'd like to show data also on the plot. – MYaseen208 Jul 04 '11 at 09:48
-
1@MYaseen208: Please post a reproducible example, as detailed here: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Ari B. Friedman Jul 04 '11 at 10:05
-
Don't bother. Show a table instead. – Gavin Simpson Jul 04 '11 at 11:04
1 Answers
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)

rcs
- 67,191
- 22
- 172
- 153
-
2Check 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
-
-
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