adding legend for colored nodes indicating bootstrap values

556 views
Skip to first unread message

Mark Phuong

unread,
Nov 17, 2016, 12:06:19 AM11/17/16
to ggtree
Hi Guangchuang,

Hope you are doing well. Many thanks for this great rpackage. I am having trouble figuring out how to generate a legend that shows how bootstrap values are colored on my tree. My code and input files are attached below. Do you have any ideas?

Many thanks,

Mark

conus.tree.boot <- read.raxml("RAxML_bipartitionsBranchLabels.conus_32_exon_cap")

pbs <- ggtree(conus.tree.boot)

conus.tree <- read.nexus("conus_tree_32_calibrated.nexus")

p <- ggtree(conus.tree)
p$data$bootstrap <- as.numeric(pbs$data$bootstrap)

cols <- c("100" = "black", "95-99" = "#56B4E9", "60-95" = "#D55E00")

p + geom_point2(aes(subset=!is.na(bootstrap) & bootstrap ==100,label = "100", color="100") ) +
  geom_point2(aes(subset=!is.na(bootstrap)  & bootstrap >95 & bootstrap < 100, label="95-99", color="95-99")) + 
  geom_point2(aes(subset=!is.na(bootstrap)  & bootstrap <95, label="60-95", color="60-95")) + 
  geom_treescale(x=10, y=10) + 
  geom_tiplab(offset=2) + xlim(0,200) +
  scale_color_manual(name = "bootstrap", breaks=c("100", "95-99", "60-95"), values = cols,  labels = c("100", "95-99", "60-95"))
conus_tree_32_calibrated.nexus
RAxML_bipartitionsBranchLabels.conus_32_exon_cap

Yu, Guangchuang

unread,
Nov 17, 2016, 12:31:02 AM11/17/16
to Mark Phuong, ggtree
just + theme(legend.position="right")

--
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/233f5587-f988-4f8a-89a0-ca4b35ef4d90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu, PhD Candidate
State Key Laboratory of Emerging Infectious Diseases
School of Public Health
The University of Hong Kong
Hong Kong SAR, China
-~----------~----~----~----~------~----~------~--~---

Mark Phuong

unread,
Nov 17, 2016, 12:35:32 AM11/17/16
to ggtree
ah thanks! that's what I was missing.


On Wednesday, November 16, 2016 at 9:31:02 PM UTC-8, Yu, Guangchuang wrote:
just + theme(legend.position="right")
On Thu, Nov 17, 2016 at 1:06 PM, Mark Phuong <markp...@gmail.com> wrote:
Hi Guangchuang,

Hope you are doing well. Many thanks for this great rpackage. I am having trouble figuring out how to generate a legend that shows how bootstrap values are colored on my tree. My code and input files are attached below. Do you have any ideas?

Many thanks,

Mark

conus.tree.boot <- read.raxml("RAxML_bipartitionsBranchLabels.conus_32_exon_cap")

pbs <- ggtree(conus.tree.boot)

conus.tree <- read.nexus("conus_tree_32_calibrated.nexus")

p <- ggtree(conus.tree)
p$data$bootstrap <- as.numeric(pbs$data$bootstrap)

cols <- c("100" = "black", "95-99" = "#56B4E9", "60-95" = "#D55E00")

p + geom_point2(aes(subset=!is.na(bootstrap) & bootstrap ==100,label = "100", color="100") ) +
  geom_point2(aes(subset=!is.na(bootstrap)  & bootstrap >95 & bootstrap < 100, label="95-99", color="95-99")) + 
  geom_point2(aes(subset=!is.na(bootstrap)  & bootstrap <95, label="60-95", color="60-95")) + 
  geom_treescale(x=10, y=10) + 
  geom_tiplab(offset=2) + xlim(0,200) +
  scale_color_manual(name = "bootstrap", breaks=c("100", "95-99", "60-95"), values = cols,  labels = c("100", "95-99", "60-95"))

--
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...@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/233f5587-f988-4f8a-89a0-ca4b35ef4d90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Phuong

unread,
Dec 3, 2016, 1:56:29 PM12/3/16
to ggtree
Hi Guangchuang,

Hope you are doing well. I am having trouble adjusting the horizontal justification of my legend title. Here is my code:

p + geom_point2(aes(subset=!is.na(bootstrap) & bootstrap ==100,label = "100", color="100") ) +
  geom_point2(aes(subset=!is.na(bootstrap)  & bootstrap >95 & bootstrap < 100, label="95-99", color="95-99")) + 
  geom_point2(aes(subset=!is.na(bootstrap)  & bootstrap <95, label="60-94", color="60-94")) + 
  geom_treescale(x=10, y=10, width=10) + 
  geom_tiplab(offset=2) + xlim(0,200) +
  scale_color_manual(name="bootstrap", breaks=c("100", "95-99", "60-94"), values = cols,  labels = c("100", "95-99", "60-94")) +
  theme(legend.position=c(.1,.48), legend.title.align=0.5, legend.title=element_text(size=10))

No matter what I do, the legend title text is aligned to the left. I also tried inserting this into the scale_color_manual:

guide = guide_legend(title="bootstrap", title.hjust=0.5, title.position = "top", size=8)

However, title.vjust works when I set title.position to "left" :

(guide = guide_legend(title="bootstrap", title.vjust=1, title.position = "left", size=8)

and in that case, I can adjust title.vjust -- do you have any advice on how to fix  this?

Many thanks!

Mark
Reply all
Reply to author
Forward
0 new messages