[R] Multiple colors in plots/lookup function

Richard Nixon richard.nixon at mrc-bsu.cam.ac.uk
Thu Oct 17 11:06:00 CEST 2002


 
> Hello,
>   I'd like to do something like:
> 
>  n<-100
>  zz<-cbind(rnorm(n),rnorm(n),floor(runif(n)*3+1))
>  colors<-c("red","green","blue")
> 
>  plot(zz,col=colors(zz[3]))
> 
> and have a matrix of scatterplots colored by class.  The above does not
> work, of course, but I'm not sure exactly what function I'm looking for.
> 

Dave,
Not quite sure what you are after. Are you wanting to plot n vs zz for each 
column of zz?. If so try this...

n <- 100
zz <- cbind(rnorm(n),rnorm(n),floor(runif(n)*3+1))
colors<-c("red","green","blue")
for(i in 1:3){
    plot(1:n,zz[,i],col=colors[i],ylim=range(zz))
    par(new=T)
}

or a pairs type plot. In which case something like this will do (not sure what 
you mean about the colours in this case)

par(mfrow=c(3,3))
for(i in 1:3){
    for(j in 1:3){
        plot(zz[,i],zz[,j],col=colors[i],ylim=range(zz), xlim=range(zz))
    }
}

Richard

--
Dr. Richard Nixon
MRC Biostatistics Unit, Cambridge, UK
http://www.mrc-bsu.cam.ac.uk/personal/richard
Tel: +44 (0)1223 330382, Fax: +44 (0)1223 33038

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list