[R] Selecting / creating unique colours for behavioural / transitional data

Kingsford Jones kingsfordjones at gmail.com
Sat Mar 14 20:35:14 CET 2009


On Fri, Mar 13, 2009 at 7:58 AM, Ross Culloch <ross.culloch at dur.ac.uk> wrote:
>
> Hi Kingsford,
>
> Thanks yet again for your help! I have tried this, and once again i have
> failed! I have put the code that i've used below (i'm sure you'll note some
> bad practice)

It doesn't appear you changed the factor to a character.  Here's a
reproducible example using 4 colors (but 15 should work the same way)

#install.packages(c('TraMineR', 'epitools'))
library(TraMineR); library(epitools)
data(actcal)
mycols <- colors.plot(T) #left-click on 4 colors of choosing
#then right-click to 'Stop'
mycols <- as.character(mycols[,3])
seqiplot(seqdef(actcal,13:24), cpal=mycols)


If you type "choosing colors" without the quotes into RSeek you will
see many options for choosing colors in R.  Be sure to notice the tabs
for various types of output in the RSeek results page ('Support
Lists', 'Functions', ...).


hth,
Kingsford Jones

> if that is any use to help explain where i'm going wrong, it
> seems to run fine and feeds back just what you noted it would, but i still
> get the error message as before - if you have any more suggestions i'd be
> very greatful, i'm sure it is down to me missing something very simple!
>
> Thanks again,
>
> Ross
>
>> mycols <- colors.plot(T)
>> str(mycols$color.names)
>  Factor w/ 15 levels "slategray2","snow3",..: 9 10 11 12 13 14 15 1 2 3 ...
>> ##Factor w/ 4 levels "blue","green",..: 3 4 2 1
>> str(as.character(mycols$color.names))
>  chr [1:15] "tomato1" "tomato4" "turquoise1" "violet" "violetred4" "wheat3"
> ...
>> ##chr [1:4] "tomato1" "yellow1" "green" "blue"
>>
>> attach(dd)
>> seqiplot(data.seq[1:4,], withlegend=FALSE, ylab="Seal ID",
> + axes = F, title = "30-09-2008", cpal=mycols)
> There were 12 warnings (use warnings() to see them)
>> y.lab.pos <-  c(0.7, 1.9, 3.1, 4.3)
>> axis(2, at=y.lab.pos, labels=paste(ID[1:4], sep=""), tick=FALSE)
>> detach(dd)
>
>
>
> Kingsford Jones wrote:
>>
>> On Fri, Mar 13, 2009 at 7:19 AM, Ross Culloch <ross.culloch at dur.ac.uk>
>> wrote:
>>>
>>> Many thanks yet again for your reply, thanks for that method, i gave it a
>>> go
>>> and i checked 'mycols' and sure enough it had selected the chosen colours
>>> and listed their names, but when i used it for making the graph warnigs
>>> informed me that the supplied colour in not numeric or character.
>>
>>
>> The data frame holds is storing the colors as class factor.  You'll
>> need to convert to character.  Note
>>
>>> mycols <- colors.plot(T)
>>> str(mycols$color.names)
>>  Factor w/ 4 levels "blue","green",..: 3 4 2 1
>>> str(as.character(mycols$color.names))
>>  chr [1:4] "tomato1" "yellow1" "green" "blue"
>>
>>
>> hth,
>> Kingsford
>>
>>
>>>
>>> Ross
>>>
>>>
>>>
>>> Kingsford Jones wrote:
>>>>
>>>> One option for creating your own palette is
>>>>
>>>> #install.packages('epitools')
>>>> mycols <- colors.plot(locator = TRUE)
>>>>
>>>> then left-click on 15 colors of your liking and then right-click 'Stop'.
>>>>
>>>> mycols will be a data.frame with the third column containing the color
>>>> names.
>>>>
>>>> Kingsford
>>>>
>>>> On Fri, Mar 13, 2009 at 6:38 AM, Ross Culloch <ross.culloch at dur.ac.uk>
>>>> wrote:
>>>>>
>>>>> Hi Kingsford,
>>>>>
>>>>> Thanks for the reply - some of the sets/palettes in the RColorBrewer
>>>>> are
>>>>> ideal, but the problem with the problem i have is that they only go up
>>>>> to
>>>>> 12
>>>>> colours, and i need 15 colours - so i assume the only thing i can do is
>>>>> create my own palette, but i'm having limited success in trying to work
>>>>> out
>>>>> how to do this.
>>>>>
>>>>>
>>>>> Kingsford Jones wrote:
>>>>>>
>>>>>> Try
>>>>>>
>>>>>> #install.packages('RColorBrewer')
>>>>>> example(brewer.pal, pack='RColorBrewer')
>>>>>>
>>>>>>
>>>>>> hth,
>>>>>> Kingsford Jones
>>>>>>
>>>>>> On Fri, Mar 13, 2009 at 3:20 AM, Ross Culloch <ross.culloch at dur.ac.uk>
>>>>>> wrote:
>>>>>>>
>>>>>>> Dear all,
>>>>>>>
>>>>>>> This seems like a simple problem but i've searched the help files and
>>>>>>> tried
>>>>>>> various options but failed, so apologies in advance for asking what
>>>>>>> i'm
>>>>>>> sure
>>>>>>> is an easy thing to do!
>>>>>>>
>>>>>>> In short, I have displayed behavioural data using the TraMineR
>>>>>>> package
>>>>>>> such
>>>>>>> that there is a colour change between the transition of behaviours,
>>>>>>> however,
>>>>>>> all the methods that i have used thus far have given me gradual
>>>>>>> changes
>>>>>>> in
>>>>>>> colour such that it is impossible to tell the difference from several
>>>>>>> of
>>>>>>> the
>>>>>>> behaviours. I have looked in the help section here, and looked at
>>>>>>> various
>>>>>>> books and help files in R, but most seem intent on gradual changes in
>>>>>>> colour
>>>>>>> for heat, terrain, depth, etc - i may not be looking in the correct
>>>>>>> places,
>>>>>>> or perhaps i don't know what i'm looking for, exactly.
>>>>>>>
>>>>>>> The code below is the closest i can get to colours being not too
>>>>>>> similar,
>>>>>>> but it's still hard to tell apart:
>>>>>>>
>>>>>>> col <- rainbow(15,start = 0, end = 1, gamma = 0.5)
>>>>>>>
>>>>>>> What i ideally want to do is create a palette with random colours
>>>>>>> that
>>>>>>> are
>>>>>>> no where near one another so that i can tell the 15 different
>>>>>>> behaviours
>>>>>>> apart - is this possible?
>>>>>>>
>>>>>>> If anyone can help i would be most greatful!
>>>>>>>
>>>>>>> Best wishes,
>>>>>>>
>>>>>>> Ross
>>>>>>> --
>>>>>>> View this message in context:
>>>>>>> http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22492438.html
>>>>>>> Sent from the R help mailing list archive at Nabble.com.
>>>>>>>
>>>>>>> ______________________________________________
>>>>>>> R-help at 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.
>>>>>>>
>>>>>>
>>>>>> ______________________________________________
>>>>>> R-help at 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.
>>>>>>
>>>>>>
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22495482.html
>>>>> Sent from the R help mailing list archive at Nabble.com.
>>>>>
>>>>> ______________________________________________
>>>>> R-help at 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.
>>>>>
>>>>
>>>> ______________________________________________
>>>> R-help at 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.
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22496241.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> ______________________________________________
>>> R-help at 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.
>>>
>>
>> ______________________________________________
>> R-help at 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.
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22496949.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>




More information about the R-help mailing list