[R] colours legend, for loop,density plot

Jim Lemon jim at bitwrit.com.au
Mon Nov 11 23:59:58 CET 2013


On 11/12/2013 09:52 AM, Mª Teresa Martinez Soriano wrote:
> normal<-sort(rnorm(1000))	cauchy<-sort(rcauchy(1000))	t3<-sort(rt(1000,3))	t10<-sort(rt(1000, 10))
> 	col<-c("green","blue","orange","purple")	v<-list(normal,cauchy,t3,t10)	names(v)<-c("Normal", "Cauchy", "T-stud 3 df", "T-stud 10 df")
> 	par(mfrow=c(1,2))		plot(density(normal),col=col[[1]],main="Funciones de densidad")	for ( i in 2:4)	{	lines(density(v[[i]]),col=col[[i]],lty=i+2)	}
> 	legend(x=-4,y=0.3,names(v),col=col,cex=0.6)
>
Hi Tere,
Try this:

legend(x=-2,y=0.04,names(v),col=col,cex=0.6,lty=c(1,4:6))

Jim



More information about the R-help mailing list