how to modify some tiplabs in ggtree?
Hi there,
I am creating a tree with ggtree and the only thing I am not able to do is to modify some tiplabs (only some! ) in the tree. This is my command:
tree = read.tree(text = "XXXXX;")
p <- ggtree(tree)
## create a data frame that contains the taxa name and the country:
dd <- data.frame(taxa = c("y","z","d"),
Location = c(rep("here", 2), rep("there", 1)))
row.names(dd) <- NULL
print(dd)
### do the tree (use dev.off())
p <- p %<+% dd + geom_tippoint(aes(color=Location),size=6)
p+theme(legend.position="right")+
scale_color_brewer("Location", palette="Dark2")+
geom_tiplab(size=3.5,hjust =-0.1)+
xlim(NA, 0.15)
I have read that with "geom_tiplab" is posible to change the style of the text but for the whole tree and I don't want that.
Any idea?
Thank you so much
• 5,241 views
•
link
1 answer
This might help https://groups.google.com/g/bioc-ggtree/c/Ciy4Fh_7hl4
library(ape)
library(ggtree)
tree <- rcoal(5)
tree$tip.label <- c("REF-1","REF-2","S1","S2","S3")
full_tree <- ggtree(tree) + xlim(0,2) + geom_tiplab()
full_tree
#Since we know the first two are reference, use the order
limited_tree1 <- ggtree(tree) + xlim(0,2) + geom_tiplab(aes(subset=(node %in% c(1,2))))
limited_tree1
#But we also know the names are different, so we can use that as well
#grepl() searches for 'RE' in the label, and returns true if found
#we use aes(subset=()) to only print those with the subset condition == TRUE
limited_tree2 <- ggtree(tree) + xlim(0,2) + geom_tiplab(aes(
subset=(grepl('RE',label,fixed=TRUE)==TRUE)))
limited_tree2
• 0 views
•
link
Log in to answer this question.
Were you able to figure this out? I'm looking for an answer to this as well, but to change hjust position for a subset of taxa/tip labels. Please let me know if you figured this out.