Hi there, as I'm not sure to understand the coloring levelplot uses, I'm looking for another easy way to create a heatmap like this: library(lattice) mat <- matrix(seq(1,5, length.out = 12), nrow = 3) mat[1,2] <- 3.5 my.at <- seq(0.5,5.5, length.out = 6) my.col.regions <- rainbow(5) graph <- levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions = my.col.regions) print(graph) Can anybody help me with some hints or little examples? Antje
Antje <niederlein-rstat <at> yahoo.de> writes:> as I'm not sure to understand the coloring levelplot uses, I'm looking for > another easy way to create a heatmap like this: > > library(lattice) > mat <- matrix(seq(1,5, length.out = 12), nrow = 3) > mat[1,2] <- 3.5 > > my.at <- seq(0.5,5.5, length.out = 6) > my.col.regions <- rainbow(5) > > graph <- levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions = > my.col.regions) > print(graph) >Looks fine to me, so what's wrong? Maybe have a look at RColorBrewer to get more pleasing colors. Dieter
Antje wrote:> Hi there, > > as I'm not sure to understand the coloring levelplot uses, I'm looking > for another easy way to create a heatmap like this: > > library(lattice) > mat <- matrix(seq(1,5, length.out = 12), nrow = 3) > mat[1,2] <- 3.5 > > my.at <- seq(0.5,5.5, length.out = 6) > my.col.regions <- rainbow(5) > > graph <- levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions = > my.col.regions) > print(graph) > > Can anybody help me with some hints or little examples?Dear Antje, since you are asking the same question again now, maybe you can explain what you are going to get? In fact, I do not undertsand where your problem is. R places the colors according to the values in your matrix very well including the legend and I thought up to today that the plot is self explaining. Best wishes, Uwe Ligges> Antje > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
The image function in base graphics does the same type of plot, just different names and structure of the data (and the documentation says that the number of breaks should be 1 more than the number of colors). Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Antje > Sent: Tuesday, May 05, 2009 1:12 AM > To: r-help at stat.math.ethz.ch > Subject: [R] Heatmap without levelplot > > Hi there, > > as I'm not sure to understand the coloring levelplot uses, I'm looking > for > another easy way to create a heatmap like this: > > library(lattice) > mat <- matrix(seq(1,5, length.out = 12), nrow = 3) > mat[1,2] <- 3.5 > > my.at <- seq(0.5,5.5, length.out = 6) > my.col.regions <- rainbow(5) > > graph <- levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions > my.col.regions) > print(graph) > > Can anybody help me with some hints or little examples? > > Antje > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.