[R] Colours on conditional levelplots in package "lattice"
Dieter Menne
dieter.menne at menne-biomed.de
Sat Aug 7 19:14:23 CEST 2010
gordon.morrison wrote:
>
> I am having difficulty in getting the colours on a conditional levelplot
> in
> the package lattice to work as I want them to - I wonder if someone could
> help me.
>
I did not understand exactly what you wanted because the example was a bit
complext, but the following comes closer to your requests:
require(lattice)
#col1 <-
c(1.37,2.35,0.20,1.85,0.274,1.56,-0.76,-0.03,-1.39,-0.95,-0.50,0.91,1.58,0.17,-0.34,-0.48,1.50,-0.68,1.05)
col2 <-
c("A","B","C","F","G","H","B","C","E","G","H","A","B","C","D","E","F","G","H")
col3 <-
c("X","Y","X","Y","X","Y","Y","X","X","X","Y","X","Y","X","Y","X","Y","X","Y")
col4 <-
c("1","1","1","1","1","1","2","2","2","2","2","3","3","3","3","3","3","3","3")
dat1 <- data.frame(X1=col1, var1=col2, var2=col3, var3=col4)
dat1$X1 = 1:nrow(dat1)-nrow(dat1)/2
maxAbsValue <- max(abs(as.vector(dat1[, "X1"])))
colorkeyAt <- pretty(c(-maxAbsValue, maxAbsValue), n = 10)
boxColours <- c("#8B0000", "#A83500", "#C46B00", "#E2A100", "#FFD700",
"#ADD8E6", "#81A2CF", "#566CB8", "#2B36A1", "#00008B")
levelplot(X1 ~ var1 * var2 | var3, data = dat1,
col.regions = boxColours,
colorkey = list(at = colorkeyAt,
labels = list(labels = colorkeyAt, at = colorkeyAt,
cex =0.6)),
at = pretty(c(-maxAbsValue, maxAbsValue), n = 10),
panel = function(x, y, z, ...) {
panel.fill(col = "darkgrey")
panel.levelplot(x, y, z,...)
})
--
View this message in context: http://r.789695.n4.nabble.com/Colours-on-conditional-levelplots-in-package-lattice-tp2316446p2317330.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list