Thanks a lot Rui, It helps :) I can modify this according to my need.. I didn't know about rle function. Thanks again, Mitra
On 21 June 2013 23:32, Rui Barradas <ruipbarra...@sapo.pt> wrote: > Hello, > > I'm not sure I understand. You want to attribute a color number 1:7 to > each element of your vector? Maybe the following will do. > > > x <- scan(text = " > > 43 43 43 43 0 39 13 39 50 39 39 23 23 32 0 13 32 23 32 23 0 13 13 0 > ") > > cols <- rep(1:7, rle(x[order(x)])$lengths)[**order(order(x))] > plot(x, col = cols) > > > Hope this helps, > > Rui Barradas > > Em 21-06-2013 16:13, Suparna Mitra escreveu: > >> Hello R experts, >> I want to define desired numbers to a vector based on the present >> numbers. Can anybody please help me? >> Obviously I found worst ways to do it, but I believe there must be any >> better way. >> >> I have vector as >> >>> X >>> >> [1] 43 43 43 43 0 39 13 39 50 39 39 23 23 32 0 13 32 23 32 23 0 13 >> 13 0 >> Now I want to colour a plot with unic cols based on this vector. I want to >> baseplot. >> But now the problem in normal col pallet these nos has repetition. Thus I >> tried to >> library(RColorBrewer) >> >>> coll<-colorRampPalette(brewer.**pal(9, "Set1"))(50) >>> >> and then use this vector as col. >> >> But there also the colours are not enough bright. >> >> So I am trying to set new a vector reading this present vector. >> Obviously I can type out manually as >> coll=c(rep(1,4),0,2 .... >> >> But rather I am trying for some automation with which function or similar >> But still now I am struggling with this. >> Can anybody please help me. >> >> Basic thing is some way to reads the vector and define a new col vector >> from 1:7 >> >> Thanks a lot, >> Mitra >> >> [[alternative HTML version deleted]] >> >> ______________________________**________________ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> >> PLEASE do read the posting guide http://www.R-project.org/** >> posting-guide.html <http://www.R-project.org/posting-guide.html> >> and provide commented, minimal, self-contained, reproducible code. >> >> [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.