Italics and regular text in phylogeny.

The following code will depict a phylogenetic tree with tip marks in italics, and underscores replaced with spaces.

library(ape)
tr <- rtree(5, tip.label=c("a_b_x1", "b_c_2", "c_d_3y", "d_e_4", "e_f_5"))
plot(tr)

How to combine plain text with italic text in label labels on phylogenesis? I am interested in letters in italics and the alphanumeric segment after the last underscore displayed as plain text.

I tried using expressionwith tiplabels, but this does not work due to the interpretation of indexing. Also failed to format subto select two parts in expression.

tip <- unlist(strsplit("a_b_x1", "_"))
tiplabels(expression(italic(paste(tip[1:length(tip)-1], collapse = " ")) * tip[length(tip)]), 
    tip = which(tr$tip.label == "a_b_x1"), frame = "n", bg = "white")
+4
source share
1 answer

We can build expressions with bquote:

library(ape)
set.seed(1)
tr <- rtree(5, tip.label=c("a_b_x1", "b_c_2", "c_d_3y", "d_e_4", "e_f_5"))
plot(tr, show.tip.label = F)

for(i in seq_along(tr$tip.label)){
    tip <- unlist(strsplit(tr$tip.label[i], "_"))

    tiplabels(
        bquote(italic(.(paste(tip[-length(tip)], collapse = ' '))) ~ .(tip[length(tip)])),
        tip = i, adj = c(0, 0.5), frame = "n", bg = "white"
    )

}

enter image description here

+1

Source: https://habr.com/ru/post/1674695/


All Articles