Reputation: 159
I am using the R package ape
to draw phylogenetic trees. Some of the labels that are displayed are not of direct interest to me (e.g., "CAN", see image below) and some of them overlap (e.g., "B10", "D1" or "D3"). The idea would be to: (1) find a way to prevent some of the labels from being displayed, or (2) decrease font size to make the labels more readable.
Here is the code that I used to plot the tree:
library(ape)
arbol <- nj(as.dist(Matrix_Distance))
plot.phylo(arbol, type = "unrooted", edge.width = 1, font = 1,lab4ut = "axial", show.tip.label = TRUE, cex = 0.5)
Here is the dput()
for the Matrix_Distance
matrix:
Matrix_Distance <- structure(c(0, 0.326511506251481, 0.336006086921219, 0.0444988056126707,
0.0480867845389803, 0.0503019236019748, 0.0374190142347097, 0.044474378005598,
0.0495784849816714, 0.0376867344270165, 0.0379398897604375, 0.199202292123909,
0.200410050450334, 0.330229533194149, 0.336736047551321, 0.192383188880773,
0.0963655296763318, 0.0452457156018548, 0.0459338875869661, 0.0520404126026609,
0.326511506251481, 0, 0.277738407973838, 0.326027271922371, 0.329568087515665,
0.328551854053512, 0.328442686320933, 0.325848806029151, 0.325351105074129,
0.333090129724386, 0.33062905751089, 0.351548041828749, 0.35298522688544,
0.278038721695356, 0.280444201259627, 0.347785267127948, 0.317880376701051,
0.331310062984989, 0.334259421551803, 0.33321321720163, 0.336006086921219,
0.277738407973838, 0, 0.335219063735799, 0.335375425728176, 0.332607795984944,
0.333624302483247, 0.334027396919537, 0.334805995833275, 0.335455392618241,
0.336176687192981, 0.356303015361001, 0.35991484492754, 0.0140578030166058,
0.0144763669722533, 0.361289001237283, 0.322368619083354, 0.339550052850274,
0.334620165238968, 0.334520636092453, 0.0444988056126707, 0.326027271922371,
0.335219063735799, 0, 0.0400897398776824, 0.0402562647662547,
0.0414107144955124, 0.00533124050947717, 0.0391928609558206,
0.0427009237803975, 0.0435719247828981, 0.191082014943474, 0.197090480513609,
0.330060002985445, 0.331576321436942, 0.194190923742177, 0.0987412452322503,
0.0426289828094761, 0.0411839645860355, 0.0493718669337317, 0.0480867845389803,
0.329568087515665, 0.335375425728176, 0.0400897398776824, 0,
0.00454773013981058, 0.0400728473448956, 0.0407189164844416,
0.00482284749281307, 0.045823214324788, 0.0445233775660656, 0.195961845095479,
0.195672881728697, 0.333832538512492, 0.334608164905294, 0.195649893475027,
0.0968066707407677, 0.0430605330700204, 0.0434531283254102, 0.0539686262771277,
0.0503019236019748, 0.328551854053512, 0.332607795984944, 0.0402562647662547,
0.00454773013981058, 0, 0.0390674431248307, 0.0406523361332636,
0.00268044509675024, 0.0462499761541193, 0.0450677605762003,
0.194849231667258, 0.195399409244883, 0.333084236549372, 0.337895157995945,
0.195224367762397, 0.0968295660915616, 0.0434429045722447, 0.044646027345151,
0.0527555979590115, 0.0374190142347097, 0.328442686320933, 0.333624302483247,
0.0414107144955124, 0.0400728473448956, 0.0390674431248307, 0,
0.00503397088784229, 0.0423027945795776, 0.00186442780875119,
0.00530974368995733, 0.199302539132322, 0.199995474885383, 0.333474261863549,
0.335187241997379, 0.199733796648274, 0.103691542371057, 0.0470613290896341,
0.0471122945287453, 0.0530235459194857, 0.044474378005598, 0.325848806029151,
0.334027396919537, 0.00533124050947717, 0.0407189164844416, 0.0406523361332636,
0.00503397088784229, 0, 0.00681699975100358, 0.0441748944665067,
0.003522575395536, 0.199770392807277, 0.197741744940629, 0.333853257134419,
0.33582505480648, 0.198483330686744, 0.103148545689295, 0.0477440505751682,
0.0445732489871238, 0.055186206944818, 0.0495784849816714, 0.325351105074129,
0.334805995833275, 0.0391928609558206, 0.00482284749281307, 0.00268044509675024,
0.0423027945795776, 0.00681699975100358, 0, 0.039420637717289,
0.0422282283194595, 0.194256396504509, 0.195856326510698, 0.330068213529374,
0.335903033931699, 0.194416823513667, 0.0961000771643727, 0.0433900961812807,
0.0427593691418318, 0.0519440981058184, 0.0376867344270165, 0.333090129724386,
0.335455392618241, 0.0427009237803975, 0.045823214324788, 0.0462499761541193,
0.00186442780875119, 0.0441748944665067, 0.039420637717289, 0,
0.0390702469624961, 0.197659208886204, 0.198154699676583, 0.327367819084691,
0.332485733577357, 0.19488214965918, 0.100586838253038, 0.0450055381921049,
0.0415899238627063, 0.0519147495479087, 0.0379398897604375, 0.33062905751089,
0.336176687192981, 0.0435719247828981, 0.0445233775660656, 0.0450677605762003,
0.00530974368995733, 0.003522575395536, 0.0422282283194595, 0.0390702469624961,
0, 0.193243216543313, 0.192716414780958, 0.331500798269211, 0.332278217436312,
0.192354218097537, 0.0986226942472296, 0.0426762753334572, 0.0427290342074088,
0.0485044666051026, 0.199202292123909, 0.351548041828749, 0.356303015361001,
0.191082014943474, 0.195961845095479, 0.194849231667258, 0.199302539132322,
0.199770392807277, 0.194256396504509, 0.197659208886204, 0.193243216543313,
0, 0.188327278515924, 0.319803751206133, 0.320450936911227, 0.184680747074505,
0.0016830999405719, 0.102543989109571, 0.102929829171427, 0.0985319020732606,
0.200410050450334, 0.35298522688544, 0.35991484492754, 0.197090480513609,
0.195672881728697, 0.195399409244883, 0.199995474885383, 0.197741744940629,
0.195856326510698, 0.198154699676583, 0.192716414780958, 0.188327278515924,
0, 0.00996509651300943, 0.361098737043685, 0.360763784891108,
0.00925831234565036, 0.200678422180443, 0.197633497229289, 0.197602528974878,
0.330229533194149, 0.278038721695356, 0.0140578030166058, 0.330060002985445,
0.333832538512492, 0.333084236549372, 0.333474261863549, 0.333853257134419,
0.330068213529374, 0.327367819084691, 0.331500798269211, 0.319803751206133,
0.00996509651300943, 0, 0.360702907713455, 0.363054305844546,
0.00879489890519423, 0.197861665955482, 0.200169731748693, 0.195047488054228,
0.336736047551321, 0.280444201259627, 0.0144763669722533, 0.331576321436942,
0.334608164905294, 0.337895157995945, 0.335187241997379, 0.33582505480648,
0.335903033931699, 0.332485733577357, 0.332278217436312, 0.320450936911227,
0.361098737043685, 0.360702907713455, 0, 0.0135127552832453,
0.361907005213846, 0.336605263172587, 0.33593078154814, 0.331371565318138,
0.192383188880773, 0.347785267127948, 0.361289001237283, 0.194190923742177,
0.195649893475027, 0.195224367762397, 0.199733796648274, 0.198483330686744,
0.194416823513667, 0.19488214965918, 0.192354218097537, 0.184680747074505,
0.360763784891108, 0.363054305844546, 0.0135127552832453, 0,
0.359861893571362, 0.336656360746836, 0.334253860842037, 0.333018174065755,
0.0963655296763318, 0.317880376701051, 0.322368619083354, 0.0987412452322503,
0.0968066707407677, 0.0968295660915616, 0.103691542371057, 0.103148545689295,
0.0961000771643727, 0.100586838253038, 0.0986226942472296, 0.0016830999405719,
0.00925831234565036, 0.00879489890519423, 0.361907005213846,
0.359861893571362, 0, 0.199382445122727, 0.197320501995477, 0.191867695619231,
0.0452457156018548, 0.331310062984989, 0.339550052850274, 0.0426289828094761,
0.0430605330700204, 0.0434429045722447, 0.0470613290896341, 0.0477440505751682,
0.0433900961812807, 0.0450055381921049, 0.0426762753334572, 0.102543989109571,
0.200678422180443, 0.197861665955482, 0.336605263172587, 0.336656360746836,
0.199382445122727, 0, 0.00322819864061239, 0.0541256629080693,
0.0459338875869661, 0.334259421551803, 0.334620165238968, 0.0411839645860355,
0.0434531283254102, 0.044646027345151, 0.0471122945287453, 0.0445732489871238,
0.0427593691418318, 0.0415899238627063, 0.0427290342074088, 0.102929829171427,
0.197633497229289, 0.200169731748693, 0.33593078154814, 0.334253860842037,
0.197320501995477, 0.00322819864061239, 0, 0.0531978315034261,
0.0520404126026609, 0.33321321720163, 0.334520636092453, 0.0493718669337317,
0.0539686262771277, 0.0527555979590115, 0.0530235459194857, 0.055186206944818,
0.0519440981058184, 0.0519147495479087, 0.0485044666051026, 0.0985319020732606,
0.197602528974878, 0.195047488054228, 0.331371565318138, 0.333018174065755,
0.191867695619231, 0.0541256629080693, 0.0531978315034261, 0), .Dim = c(20L,
20L), .Dimnames = list(c("A1", "A2", "A4", "A5", "B1", "B2",
"B3", "B4", "B10", "B12", "B15", "CAN", "C1", "C2", "C3", "C4",
"C5", "D1", "D3", "D4"), c("A1", "A2", "A4", "A5", "B1", "B2",
"B3", "B4", "B10", "B12", "B15", "CAN", "C1", "C2", "C3", "C4",
"C5", "D1", "D3", "D4")))
Upvotes: 1
Views: 2381
Reputation: 1867
Try to do it in two steps. First the tree without the tips
plot.phylo(arbol, type = "unrooted", edge.width = 1, font = 1,lab4ut = "axial", show.tip.label = FALSE)
Then the tips onto the tree
## Creating the vector of labels
my_labels <- tree$tip.label
## "Removing" the unwanted labels (e.g. label 1, 2 and 7)
my_labels[c(1,2,5)] <- ""
## Adding the labels
tiplabels(my_labels, cex = 0.5)
Upvotes: 2
Reputation: 138
According to the documentation(p.195), you can modulate the font size displayed on your tree by tuning the parameter cex
(this is a scaling factor, default being dependent on current value of the graphical parameters and might vary between users):
a numeric value giving the factor scaling of the tip and node labels (Character EXpansion). The default is to take the current value from the graphical parameters
To remove some of the labels, probably the easiest would be to remove (or hide) the corresponding column/row of the sample you don't want to display, prior to plotting. According to the docs, in fact, show.tip.label
is a boolean:
a logical indicating whether to show the tip labels on the phylogeny (defaults to TRUE , i.e. the labels are shown).
Upvotes: 2