[adegenet-forum] question colorplot

Jombart, Thibaut J X t.jombart at imperial.ac.uk
Wed Jan 14 12:31:23 CET 2009


Michael C Fontaine wrote:
> Thanks a lot for your answer. So if I'm drawing just the first PC, how can I display the scale using colorplot?
>
> Thanks again for the help!
> Michaël
>
> On 13 janv. 09, at 18:08, Jombart, Thibaut J X wrote:

In such case I would not recommand using a colorplot: s.value, or s.image (if you need interpolation) from the ade4 package would be more appropriate.

But if you want to add a legend, you could use something like:
##
par(mar=c(3,3,3,5))
xy <- matrix(runif(120),ncol=2)
z <- matrix(rnorm(60), ncol=1)
colorplot(xy,z, cex=3, xlab="", ylab="")




addLeg <- function(coords, z){
    dev.w <- abs(diff(par("usr")[1:2]))
    dev.h <- abs(diff(par("usr")[3:4]))
    x <- coords$x
    y <- coords$y
   
    res.xl <- rep(x, 10)
    res.xr <- rep(x + 0.05 * dev.w, 10)
    temp <- seq(y, dev.h*0.7, le=11)
    res.yb <- temp[1:10]
    res.yt <- temp[2:11]
   
      
    rect(res.xl, res.yb, res.xr, res.yt, col=col)
   
    txt.x <- res.xr + 0.05*dev.w
    txt.y <- 0.5*(res.yb+res.yt)
    txt.lab <- seq(min(z), max(z), le=10)
    text(txt.x, txt.y, lab=round(txt.lab, 3))

    return()
}


par(xpd=TRUE)
addLeg(locator(1),z) # here clic for the bottom left corner of the legend

##

Cheers,

Thibaut.


-- 
######################################
Dr Thibaut JOMBART
MRC Centre for Outbreak Analysis and Modelling
Department of Infectious Disease Epidemiology
Imperial College - Faculty of Medicine
St Mary’s Campus
Norfolk Place
London W2 1PG
United Kingdom
Tel. : 0044 (0)20 7594 3658
jombart at biomserv.univ-lyon1.fr
http://biomserv.univ-lyon1.fr/%7Ejombart/
http://adegenet.r-forge.r-project.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20090114/f1ffc0be/attachment.htm 


More information about the adegenet-forum mailing list