liamrevell / phytools

GNU General Public License v3.0
207 stars 56 forks source link

How to custom change colours on the map? #64

Closed tahamimo closed 3 years ago

tahamimo commented 4 years ago

I want to be able to manually assign colours once based on species/population and once based on clades, I tried this for 64 tips: colours(tree$tip.label) <- c(rep("red", 15), rep("blue", 7), rep("orange", 6), rep("green", 4), rep("purple", 3), rep("white", 13)) but it doesn't work, giving this error:

Error in if (distinct) c[!duplicated(t(col2rgb(c)))] else c : argument is not interpretable as logical In addition: Warning message: In if (distinct) c[!duplicated(t(col2rgb(c)))] else c : the condition has length > 1 and only the first element will be used

Does anybody know how to manually set colours to each tip?

liamrevell commented 4 years ago

I don't understand the issue or the syntax. Are you trying to plot different color tips (terminal edges) on a plotted tree? Or are you doing something with phylo.to.map? Please try to post a reproducible example so that I can help.

tahamimo commented 4 years ago

I don't understand the issue or the syntax. Are you trying to plot different color tips (terminal edges) on a plotted tree? Or are you doing something with phylo.to.map? Please try to post a reproducible example so that I can help.

Or in general, if I know how can I change the default "red" colour of the lines to "white" or something invisible then I can manually draw lines myself

liamrevell commented 4 years ago

Hi Tahamimo. I don't even know which function you're using, so it's difficult for me to respond. Are you plotting the tree of your attached image but your want the terminal edges to have different colors based on the nominal taxon membership of each label?

tahamimo commented 4 years ago

Hi Liam, This is my complete code:

#convert column 1 to rownames and remove column 1
rownames(gps) <- gps$name
gps <- gps[,2:3]

obj <- phylo.to.map(tree, gps, database="world",
                    regions="Iran", plot=FALSE)

plot(obj, type="phylogram", direction="rightwards", fsize=0.6)

Are you plotting the tree of your attached image but your want the terminal edges to have different colors based on the nominal taxon membership of each label?

yes, as I explained twice in both of my previous comments, that is my intention

liamrevell commented 3 years ago

It is possible to draw the linking lines with different colors. To see how, search my blog for the function phylo.to.map -- e.g., http://blog.phytools.org/search?q=phylo.to.map.