Alex galvez morante
Alex galvez morante

Reputation: 137

Plotting tree in R with node labels

I am trying to plot a tree with previously specified node labels in Newick format:

((58_Amphimedon_queenslandica:1.271048872,59_Oscarella_carmela:1.182998044)60:0.034049179,((61_Mnemiopsis_leidyi:0.322168794,62_Pleurobrachia_bachei:0.548640591)63:1.652794394,((((((1_Adineta_vaga:1.7879779,(((2_Echinococcus_multilocularis:1.046556098,3_Schistosoma_mansoni:0.91678556)4:0.616271036,5_Schmidtea_mediterranea:1.692309447)6:0.32666239,7_Macrostomum_lignano:1.568266346)8:0.378093813)9:0.130389525,(((((10_Biomphalaria_glabrata:0.618932621,11_Lottia_gigantea:0.452269273)12:0.059417719,13_Crassostrea_gigas:0.518431208)14:0.040670598,15_Octopus_bimaculata:0.646961425)16:0.101479681,(17_Notospermus_geniculatus:0.529250964,18_Phoronis_australis:0.555407465)19:0.044453771)20:0.020365466,(21_Capitella_teleta:0.570779897,22_Helobdella_robusta:1.12545896)23:0.111068195)24:0.042564036)25:0.04351873,((((((26_Apis_mellifera:0.703550258,27_Drosophila_melanogaster:1.030363662)28:0.223325196,29_Daphnia_pulex:0.896728176)30:0.178376492,((31_Ixodes_scapularis:0.772869706,(32_Limulus_polyphemus:0.410288152,33_Stegodyphus_mimosarum:0.666118706)34:0.032501467)35:0.11894679,36_Strigamia_maritima:0.721726909)37:0.049724874)38:0.083204725,(39_Hypsibius_dujardini:0.431761707,40_Ramazzottius_varieornatus:0.877374545)41:1.393205979)42:0.016782622,(((43_Caenorhabditis_elegans:0.989355479,44_Pristionchus_pacificus:0.938419613)45:0.353607734,46_Loa_loa:0.922207873)47:0.803845621,(48_Romanomermis_culicivorax:1.176159859,(49_Trichuris_muris:1.244039486,50_Trichinella_spiralis:1.095739241)51:0.623094809)52:0.13754668)53:0.514360208)54:0.04135167,55_Priapulus_caudatus:0.755052063)56:0.038898188)57:0.075727099,(((((0_Acanthaster_planci:0.075878507,110_Patiria_miniata:0.110665648)111:0.325399251,(104_Apostichopus_japonicus:0.599326865,(105_Lytechinus_variegatus:0.129683096,106_Strongylocentrotus_purpuratus:0.059356674)107:0.376377895)108:0.051862417)109:0.16901716,((98_Ptychodera_flava:0.346722111,99_Saccoglossus_kowalevskii:0.259401265)100:0.172870001,101_Rhabdopleura_recondita:0.68730129)102:0.054777546)103:0.076162868,96_Xenoturbella_bocki:0.970285664)97:0.02334384,(78_Branchiostoma_floridae:0.56505513,((((79_Callorhinchus_milii:0.254322263,((80_Gallus_gallus:0.158525779,(81_Homo_sapiens:0.044793306,82_Mus_musculus:0.061786122)83:0.134090431)84:0.086737559,85_Latimeria_chalumnae:0.190806452)86:0.02269946)87:0.030197923,88_Danio_rerio:0.286590103)89:0.112840392,90_Petromyzon_marinus:0.506518606)91:0.246748947,92_Ciona_intestinalis:1.198840655)93:0.063420667)94:0.053862064)95:0.029924804)77:0.165620347,(69_Hydra_vulgaris:1.185855052,(70_Nematostella_vectensis:0.405991429,(71_Orbicella_faveolata:0.1188383,72_Stylophora_pistillata:0.126624764)73:0.2570364)74:0.221701033)75:0.130324524)76:0.053502655,(65_Hoilungia_hongkongensis:0.130085304,66_Trichoplax_adhaerens:0.144715451)67:1.018316539)68:0.057759319)64:0.034049179);

My code looks like this:

tree <- read.tree("/home/agalvez/data/sims/trees/rooted_tree_nodenames.txt")

tree

tree$node.label

plot(tree); nodelabels(frame = "n", cex=0.8, col= "blue")

My tree gets printed with node labels, the problem is that they are not the specified node labels in my original tree.

Thanks a lot for reading!

Upvotes: 0

Views: 2938

Answers (2)

klash
klash

Reputation: 341

Or even simpler, but with less control:

plot(tree, show.node.label = TRUE)

Upvotes: 1

Thomas Guillerme
Thomas Guillerme

Reputation: 1857

By default, the function nodelabels plots the nodes IDs (not the labels present in the tree. You can specify a text string to match these IDs using the text option:

nodelabels(text = my_text_string, node = nodes_of_interest, ...)

In your case, you can use the tree$node.label string as the text of interest (and use all the nodes by default):

nodelabels(text = tree$node.label,
           frame = "n", cex=0.8, col= "blue")

Upvotes: 0

Related Questions