Hi there, I have a question concerning the behaviour of the colouring with levelplot. (I hope, I manage to explain) If I give the parameters "at" and "col.regions" like this: at <- c(1,2,3,4,5,6) col.regions <- c("blue","blue","blue","yellow","yellow","yellow") Which color would have the value 3.5? I would have expected yellow, no? In my more complex example I wanted to create a heatmap (like yellow to red) up to a fixed threshold. All values above should get another color (like blue). Automatically, I generated both vectors like this: at <- c(vectorOfLowerValues, myThreshold, vectorOfHigherValues) col.regions <- c(vectorOfHeatmapColors, lastHeatmapColor, vectorOfColor"blue") But I get some values above the threshold which are not blue... Can anybody explain me why? (I've checked the length of both vectors and it's parts - this is correct - so 'myThreshold' would get 'lastHeatmapColor' by the same vector position) I'm very confused... Antje
Antje <niederlein-rstat <at> yahoo.de> writes:> I have a question concerning the behaviour of the colouring with levelplot. > > If I give the parameters "at" and "col.regions" like this: > > at <- c(1,2,3,4,5,6) > col.regions <- c("blue","blue","blue","yellow","yellow","yellow") > > Which color would have the value 3.5? > I would have expected yellow, no?You implicitly expect round(). [1] "blue"> col.regions[3.5][1] "blue"> col.regions[round(3.5)][1] "yellow" Your question implies that you may also susceptible to the problem of R FAQ 7.31, "Why doesn't R think these numbers are equal?" Dieter
@Dieter: > You implicitly expect round(). > Your question implies that you may also susceptible to the problem of > R FAQ 7.31, "Why doesn't R think these numbers are equal?" No, I guess, you misunderstood my question. These vectors (at and col.regions) are given to levelplot together with some data which should be visualized. I don't know how exactly levelplot works (I was asking for help to understand it) but somehow it creates something like bins from "at" and uses "col.regions" to display all datavalues within the same bin with the according color. I'd like to know, which color to expect from levelplot for a certain datavalue (3.5) Did I explain it somehow clear now? Antje
Hi Greg and all the others, thanks for your answer. The color-vector has the same length like the at-vector but the recycling cannot be the reason, because only values slightly above my "threshold" doe not appear blue. I cannot find a good explanation of which colors are assigned to which value ranges. I've made little example: #-------------------------------------------------------- mat <- matrix(seq(1,5, length.out = 12), nrow = 3) mat[1,2] <- 3.5 my.at <- seq(0.5,5.5) my.col.regions <- rainbow(6) graph <- levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions = my.col.regions) print(graph) windows() plot(1:10) legend("topleft", legend = as.character(my.col.regions), col = my.col.regions, pch = 18) #-------------------------------------------------------- As you can see the green (position 3 in my.col.regions) disappears completely in the levelplot (look at the color range at the right side!). I guess it might also happen in my case... I've tested several cases and it looks like the length of the color-vector should be one less than the at vector (which would make sense). Then, the rule might apply: [ at[1],at[2] ] = color[1] ( at[2],at[3] ] = color[2] ... ( at[n-1],at[n] ] = color[n-1] Please correct me if I'm wrong!!! Antje
Antje <niederlein-rstat <at> yahoo.de> writes:> thanks for your answer. The color-vector has the same length like the > at-vector but the recycling cannot be the reason, because only values > slightly above my "threshold" doe not appear blue. > I cannot find a good explanation of which colors are assigned to which > value ranges.This has nothing to do with the plotting, the question should be "How are float converted to integers". You had asked for that before; check my earlier reply. You implicitly assume that there is a round() function involved, but something like floor() is used. Make sure that all your numbers are integers. Dieter