Map traits at tips in different color palettes

446 views
Skip to first unread message

Edeline Gagnon

unread,
Apr 5, 2018, 6:24:47 PM4/5/18
to ggtree
Hello,
I have three qualitative traits that I would to represent at the tip of a phylogenetic tree.
I've managed to figure out how each trait could be represented by a different shape, but I would also like to be able to select different color palettes for each trait, to make it easier to read the figure.

I suspect the answer lies somewhere with scale_color_manually, but so far I haven't been able to sort it out complete. It looks as if I have to manually specify each color.

Any help to tweak this code would be appreciated.

I've included a figure of the tree i've managed to produce so far, along with my R script, and a sample of the data I'm using.
Thanks in advance!
With best regards,
Edeline

#Import tree file, as well as trait data for tips of tree.

tree2 <-read.beast(file.choose())
dd <- read.csv(file.choose())

p <- ggtree(tree2, ladderize=TRUE) +

  # Add posterior probability
  geom_text2(aes(subset=!isTip, label=round(as.numeric(posterior),2)),size=1.5, hjust=-.3, vjust=-.5) +
  # geom_text2(aes(subset=posterior<0.7, label=round(as.numeric(posterior),2)),size=1.5, hjust=-.3, vjust=-.5) +

  # Adds tip labels
 geom_tiplab(color="black",size=1.5, offset=3) +

 #This ensures that there will be space in the plot.
  xlim(0, 80)+
 
 # Adds an axis
  theme_tree2() +

 # Add point where mezoneuron fossil is MRCA(tre3,mezo) = 324
  geom_point2(aes(subset=(node ==324) ),size=2, shape=24, fill="steelblue")

 p2 <- p %<+% dd +
geom_tippoint(aes(x=x+0.5,fill = factor(Biome)),shape=21,size=2) + 
geom_tippoint(aes(x=x+1.5,fill = factor(Habit)),shape=23,size=2) +
geom_tippoint(aes(x=x+2.5,fill = factor(Geo)),shape=22,size=2)

#uncomment if you want to see the legend + theme(legend.position="right",legend.key.size = ) + scale_color_brewer(palette=2)
#suspect that this is where I would need to use scale_color_manually, but not sure how....

p2

tree4.nex
Geo_biome_habit_short.csv
Rplot04.png

Yu, Guangchuang

unread,
Apr 11, 2018, 2:49:19 AM4/11/18
to Edeline Gagnon, ggtree

--
G Yu, DK Smith, H Zhu, Y Guan, TTY Lam*. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data, Methods in Ecology and Evolution, 2017, 8(1):28-36. doi:10.1111/2041-210X.12628
 
Homepage: https://guangchuangyu.github.io/software/ggtree
---
You received this message because you are subscribed to the Google Groups "ggtree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree+unsubscribe@googlegroups.com.
To post to this group, send email to bioc-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/33802291-7fd7-4da3-9b1c-3ee2e9f3faed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu PhD
Postdoc researcher
State Key Laboratory of Emerging Infectious Diseases
School of Public Health
The University of Hong Kong
Hong Kong SAR, China
-~----------~----~----~----~------~----~------~--~---
Reply all
Reply to author
Forward
0 new messages