我正在使用ape::plot.phylo (通过phangorn::plotBS调用?)绘制一些系统发育树。问题是提示标签太长了,我想用某种方式把它们包起来。我似乎在plot或plot.phylo/plotBS中找不到任何选项来解决这个问题。
你知道怎样才能让tip.labels进行文本包装吗?
样本提示标签:"QER Echinodermata Asteroidea Asteroidea Asteriidae Asterias Asterias.rubens UNID1“
发布于 2019-05-08 08:49:50
实际上,最简单的解决方案是更改phylo对象中的tip.label元素。
## Making a tree with three tips of 20 characters each
tree <- rcoal(3, tip.label = replicate(3, paste(sample(letters, 20), collapse = "")))
## The tree tip labels
tree$tip.label
# [1] "thsdmrigufpykvlawqbz" "dlicefyjonmqugbptxzr" "adioznspgbkjqryelfum"然后,可以使用换行符(\n)对每个第n个字符进行换行,如下所示:
## Declaring the pattern and text to replace at a specific position
position <- 10
pattern <- paste0('^([a-z]{', position-1, '})([a-z]+)$')
text <- paste0('\\1', "\n", '\\2')
wrap_tips <- gsub(pattern, text, tree$tip.label)
wrap_tips
# [1] "thsdmrigu\nfpykvlawqbz" "dlicefyjo\nnmqugbptxzr" "adioznspg\nbkjqryelfum"当然,您也可以将特定字符(如_或.)替换为更简单的\n (如gsub("_", "\\n", tree$tip.label))。
然后,您可以创建树的副本,并为其提供包装的提示标签:
## Duplicating the tree
tree_to_plot <- tree
## Changing the labels
tree_to_plot$tip.label <- wrap_tips
## Plotting the wrapped labels
plot(tree_to_plot)https://stackoverflow.com/questions/56006825
复制相似问题