[R] Colours on conditional levelplots in package "lattice"
gordon.morrison at hsbcib.com
gordon.morrison at hsbcib.com
Fri Aug 6 17:13:29 CEST 2010
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.
The colours do not completely agree with the colour key.
Here is a specimen example.
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)
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)),
panel = function(x, y, z, ...) {
panel.fill(col = "darkgrey")
at = pretty(c(-maxAbsValue, maxAbsValue), n = 10)
panel.levelplot(x, y, z, ...)
})
I am hoping that all the "blue" shades appear in panel 1, the reds in panel
2 and a mixture only in panel 3. Can anyone help explain why this is not
happening?
I am using
> sessionInfo()
R version 2.11.1 (2010-05-31)
i386-pc-mingw32
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United
Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] grid grDevices datasets splines graphics stats tcltk
utils methods base
other attached packages:
[1] RColorBrewer_1.0-2 lattice_0.18-8 rcom_2.2-3 rscproxy_1.3-1
svSocket_0.9-48
[6] TinnR_1.0.3 R2HTML_2.1 Hmisc_3.8-2
survival_2.35-8
loaded via a namespace (and not attached):
[1] cluster_1.12.3 svMisc_0.9-57 tools_2.11.1
Windows XP Professional
Regards
Gordon Morrison
************************************************************
HSBC Bank plc may be solicited in the course of its placement efforts for a
new issue, by investment clients of the firm for whom the Bank as a firm
already provides other services. It may equally decide to allocate to its
own proprietary book or with an associate of HSBC Group. This represents a
potential conflict of interest. HSBC Bank plc has internal arrangements
designed to ensure that the firm would give unbiased and full advice to the
corporate finance client about the valuation and pricing of the offering as
well as internal systems, controls and procedures to identify and manage
conflicts of interest.
HSBC Bank plc
Registered Office: 8 Canada Square, London E14 5HQ, United Kingdom
Registered in England - Number 14259
Authorised and regulated by the Financial Services Authority.
************************************************************
-----------------------------------------
SAVE PAPER - THINK BEFORE YOU PRINT!
This transmission has been issued by a member of the HSBC Group
"HSBC" for the information of the addressee only and should not be
reproduced and/or distributed to any other person. Each page
attached hereto must be read in conjunction with any disclaimer
which forms part of it. Unless otherwise stated, this transmission
is neither an offer nor the solicitation of an offer to sell or
purchase any investment. Its contents are based on information
obtained from sources believed to be reliable but HSBC makes no
representation and accepts no responsibility or liability as to its
completeness or accuracy.
More information about the R-help
mailing list