[R] pairs() help - colour histograms on diagonal

Nathan S. Watson-Haigh nathan.watson-haigh at csiro.au
Tue Feb 3 02:50:46 CET 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'd like to be able to colour histograms along the diagonal using the colours
stored in colnames(d):

> d
         black        blue        brown        cyan
1   0.96405751 -0.02964390 -0.060147424 -0.06460070
2  -0.03614607  0.95475444 -0.152382053 -0.07767974
3  -0.07095613 -0.05884884 -0.061289399 -0.06445973
4  -0.03708223 -0.05997624 -0.054044275 -0.08291373
5  -0.08877190 -0.07193658 -0.078598617 -0.08892916
6  -0.09294377 -0.05563854 -0.051405213 -0.08442332
7  -0.08431200 -0.01657793 -0.119773022 -0.07364633
8  -0.06105875 -0.05311773 -0.062928495 -0.06982507
9  -0.05757523 -0.02589045 -0.102312333 -0.05616588
10 -0.05092343 -0.03935830 -0.062069716 -0.05402492
11 -0.08057353 -0.12690058 -0.004248301 -0.06850326
12 -0.08052613 -0.04962747 -0.098955086 -0.06496541
13 -0.07901151 -0.07587651 -0.077401999  0.96525294
14 -0.07187448 -0.15431262  0.952982852 -0.06471004
15 -0.07230232 -0.13704876  0.032573081 -0.05040565


panel.hist <- function(x, ...) {
    # get some graphical parameter settings, and reset them on exit
    usr <- par("usr")
	on.exit(par(usr))
	
    par(usr = c(usr[1:2], 0, 1.5) )
	
	# get a histogram of the data, but don't plot it - we just need to get some
info from the histogram
    h <- hist(x, plot = FALSE)
    breaks <- h$breaks
	nB <- length(breaks)
    y <- h$counts; y <- y/max(y)
	
    rect(breaks[-nB], 0, breaks[-1], y, ...)
}

pairs(d, upper.panel=panel.smooth, diag.panel=panel.hist)

So I'd like the top-left histogram on the diagonal to be coloured black, then
the next one on the diagonal to be coloured blue etc. Is this possible?

Cheers,
Nathan

- --
- --------------------------------------------------------
Dr. Nathan S. Watson-Haigh
OCE Post Doctoral Fellow
CSIRO Livestock Industries
Queensland Bioscience Precinct
St Lucia, QLD 4067
Australia

Tel: +61 (0)7 3214 2922
Fax: +61 (0)7 3214 2900
Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html
- --------------------------------------------------------

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmHovYACgkQ9gTv6QYzVL5bUgCgw3EHQKS9WjO2AmtEks6x0Bh9
FLgAoIFpikJ903quFBaxQe5UVXAAbrnq
=XRan
-----END PGP SIGNATURE-----




More information about the R-help mailing list