APE/Phangorn:如何包装提示标签?

APE/Phangorn:如何包装提示标签?,r,phylogeny,r-ape,R,Phylogeny,R Ape,我正在使用ape::plot.phylo,通过phangorn::plotBS调用?绘制一些系统发育树。问题是贴片标签很长,我想用某种方式把它们包起来。我似乎在plot或plot.phylo/plotBS中找不到任何选项来处理此问题 有没有办法让tip.label进行文本包装 样本提示标签:QER棘皮动物Asterozoa Asterozoa Forcipulatacea ForCipulatada Asteriidae Asterias.rubens UNID1最简单的解决方案实际上是更改ph

我正在使用ape::plot.phylo,通过phangorn::plotBS调用?绘制一些系统发育树。问题是贴片标签很长,我想用某种方式把它们包起来。我似乎在plot或plot.phylo/plotBS中找不到任何选项来处理此问题

有没有办法让tip.label进行文本包装


样本提示标签:QER棘皮动物Asterozoa Asterozoa Forcipulatacea ForCipulatada Asteriidae Asterias.rubens UNID1最简单的解决方案实际上是更改phylo对象中的tip.label元素

当然,您也可以替换特定的字符,如uo或。按\n更简单的选项,例如gsub\ux、\\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)
## 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"
## 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)