Re: [R] color for points

From: Vincent Goulet <vincent.goulet_at_act.ulaval.ca>
Date: Mon 10 Oct 2005 - 01:45:33 EST

Le 8 Octobre 2005 05:35, vincent@7d4.com a écrit :
> Sam R. Smith a écrit :
> > Hi,
> > I have the following code to randomly generate the points:
> > csr <-function(n=60){
> > x=runif(n)
> > y=runif(n)
> > f=cbind(x,y)
> > }
> > plot(csr())
> >
> > I wonder how to code to make the first twenty points to be BLUE; second
> > twenty points to be RED; the last twenty points to be GREEN?
>
> mynewfct = function(n=60)
> {
> x=runif(n)
> y=runif(n)
> f=cbind(x,y)
> plot(f[1:20] , col='blue');
> par(new=T);
> plot(f[21:40] , col='red');
> par(new=T);
> plot(f[41:60] , col='green');
> }
>
> hih

This function will plot 60 points, no matter the value of argument 'n'. Building also on Jim Holtman's comment, may I rather suggest

csr <- function(n=60)
{

	x <- cbind(runif(n), runif(n))
	plot(x, col=rep(c("blue", "red", "green"), each=20, length.out=n))
	x   # why not return the values...

}

HTH

-- 
  Vincent Goulet, Professeur agrégé
  École d'actuariat
  Université Laval, Québec 
  Vincent.Goulet_at_act.ulaval.ca   http://vgoulet.act.ulaval.ca

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Mon Oct 10 01:53:35 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:33:09 EST