0

I have a table with 4 columns, I want to extract column 1 and 3 to make a character vector. My aim is to define colour for a phylogenetic plot

Table
name    id  colour  date    
t1  a   red 10/01
t2  b   red 09/02       
t3  c   black   04/04
t4  d   black   05/05

Desired vector
cols <- c("t1"="red", "t2"="red", "t3"="black", "t4"="black")

Ive tried the suggestion from here but Its not giving me what I want. Converting two columns of a data frame to a named vector

When I execute my command to plot the phylogeny the colour matrix provided in the vector does not comply. The colours do not match what I have in the table.

For more info see my previous thread I want to colour the lines in a tanglegram using cophyloplot in ape. Argument "col=" states a character vector indicating the color to be used for the links; recycled as necessary

Community
  • 1
  • 1
AudileF
  • 436
  • 2
  • 10
  • @Cath Ive added more info. Basically when I go to plot my phylogeny the colours in the vector do not work. – AudileF May 17 '17 at 14:38
  • @Cath interger. I assume my next move is to convert this to character? Im not a wizz on R Im afraid. But would as.character be necessary? – AudileF May 17 '17 at 14:47
  • Ah cool. Ive tried several workflows including an ordered vector but no joy. My actual phylo is much bigger (92 taxa) and something must be going wrong in the execution. Thanks for the help Cath. – AudileF May 17 '17 at 14:51

1 Answers1

0

You can use the setNames function, for instance:

setNames(iris$Petal.Length, iris$Species)
fmic_
  • 2,281
  • 16
  • 23