ggtree icon indicating copy to clipboard operation
ggtree copied to clipboard

Hi Prof. Yu,

Open svedwards opened this issue 3 years ago • 0 comments
trafficstars

Hi Prof. Yu,

Thank you for a wonderful package. It really helps my science alot. I am having trouble making a figure in which the paths between a subset of nodes is made a different color. However, I would like the tips that define the pathlength (using nodepath function in ape) to have balls on them, but for some reason the balls are placed on the wrong tips, and they are the same for each tree I produce. Otherwise the figure works. I have read over various examples and I attach some code below and the tree figure with problems. Thanks for any advice!

figcells[1:8]<-c("p1","470l", "p2","086l", "p3","827l", "p4","086l", "p5","795l", "p6","373l", "p7","648l", "p8","679l")

#here is mhcmat: first column is 'node' and second column is 'included'

head(mhcmat) node included wait MCZ_Orn_365327.hap2.h2tg000373l_14465-14732 1 FALSE NA MCZ_Orn_365336.hap1.h1tg000632l_81626-81893 2 FALSE NA MCZ_orn_365326.hap2.h2tg000420l_87429-87696 3 FALSE NA _R_MCZ_orn_365338.hap2.h2tg000683l_217915-218182 4 FALSE NA _R_MCZ_Orn_365336.hap2.h2tg000455l_234891-235158 5 FALSE NA MCZ_Orn_365336.hap1.h1tg000632l_139259-139526 6 FALSE NA contig<-grep(figcells[2,8],mhcex2labels)

#here I just manually update the cell in figcells because I can't figure out how to loop it

x<-list() for(i in 1:length(contig)){ for(k in 1:length(contig)){ x<-c(nodepath(mhcex2tree, contig[i],contig[k]),x) } } contigpaths<-unlist(unique(x)) mhcmat$included[contigpaths]<-"TRUE" mhcmat$included[-contigpaths]<-"FALSE" #tree <- full_join(mhcex2tree, mhcmat, by = 'node') tree2 <- ggtree(mhcex2tree,aes(color=included),branch.length="none",size=0.5) %<+% mhcmat #it would be nice to allow the loop to create an object to which the tree2 can be written, but I can't figure out how to do that

p8<-tree2 + geom_point2(aes(subset = (node %in% contig)),color="red",size=1.5) + #this line may be what is causing the problem theme(legend.position="none") + ggtitle(mhcex2labels[contig][1],) + theme(plot.title = element_text(size = 10)) + scale_color_manual(values=c("black","red"))

fig<-ggarrange(p1,p2,p3,p4,p5,p6,p7,p8,ncol = 4, nrow = 2) ggsave(filename = "mhc_ex2_trees_fig2.pdf",fig,height = 8,width = 12)

mhc_ex2_trees_fig2.pdf

#you can see that the balls on each tree of the treefigure do not correspond to the paths in the tree. The paths are correct and different for each tree, but for some reason the balls remain the same.

Scott

Prerequisites

  • [ X] Have you read Feedback and follow the guide?
    • [ ] make sure your are using the latest release version
    • [ ] read the documents
    • [ ] google your question/issue

Describe you issue

  • [ ] Make a reproducible example (e.g. 1)
  • [X ] your code should contain comments to describe the problem (e.g. what expected and actually happened?)

Ask in right place

  • [ ] for bugs or feature requests, post here (github issue)
  • [ X] for questions, please post to google group

svedwards avatar Jan 06 '22 21:01 svedwards