The following code will plot a phylogenetic tree with tip labels 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 can I combine regular text with text in italics in tip labels on a phylogeny? I'm interested in letters in italics and alphanumeric segment after the last underscore displayed as regular text.
I tried using expression
with tiplabels
, but it does not work due to interpretation of indexing. Also formatting sub
to select the two parts in expression
failed.
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")