grunwaldlab / metacoder

Parsing, Manipulation, and Visualization of Metabarcoding/Taxonomic data
http://grunwaldlab.github.io/metacoder_documentation
Other
134 stars 28 forks source link

italicize node labels? #345

Open taylorreiter opened 1 year ago

taylorreiter commented 1 year ago

Hello! I'm curious if there is a way to italicize node labels. Since node labels are often taxonomic levels, I think this functionality could be helpful.

mcddna commented 4 months ago

Hi Taylor! I've been wanting to do the same thing! Here is a very arduous way to do it...

I found where the labels are placed on the plot by printing these...

heattreeplot$data$vx_plot heattreeplot$data$vy_plot

Note that this example was for a tree with only 37 taxa, but with internal nodes it turned out to have 83 nodes. I can't imagine using this method with a big tree of more than 100 taxa, for example.

Then I created a dataframe (tibble), one row, three cols, col1 = x, col2 = y, col3 = label. And I called it "test_var" and added labels as below (just numerals "1" through "83). Here is what I got, of course this works only with my tree, and making sure the set.seed() is the same throughout this process: (Your numbers will be different)

test_var <- tibble( x = c(0.52390636, 0.63502226, 0.47210667, 0.35278990, 0.49225149, 0.59258468, 0.62641166, 0.74129800, 0.64255159, 0.43150518, 0.30012527, 0.22189868, 0.48408978, 0.65490323, 0.71092433, 0.35542121, 0.85319553, 0.67338792, 0.39255198, 0.24461417, 0.10723864, 0.17046729, 0.51175472, 0.75093301, 0.70262324, 0.80117769, 0.29904586, 0.29849788, 0.41083165, 0.92860425, 0.73828289, 0.45573499, 0.18346290, 0.49759758, 0.05659452, 0.44620158, 0.11114748, 0.54928004, 0.78290488, 0.70858189, 0.37655126, 0.77952932, 0.90115871, 0.30861582, 0.27526748, 0.02341894, 0.85860226, 0.22826302, 0.86601086, 0.08804122, 0.46503586, 0.32729244, 0.66134614, 0.45233782, 0.34429124, 0.25758064, 0.33922625, 1.00000000, 0.79097361, 0.52016565, 0.12868891, 0.55853674, 0.00000000, 0.47123491, 0.04125609, 0.57459198, 0.66319596, 0.36155518, 0.82552550, 0.95465846, 0.84386399, 0.25398172, 0.19989023, 0.09175253, 0.75346992, 0.92212286, 0.16513345, 0.93389945, 0.67688892, 0.48069275, 0.28220728, 0.22904956, 0.35433632),

y = c(0.53079394, 0.45466655, 0.43571728, 0.59237641, 0.59761113, 0.63083319, 0.55212418, 0.45939295, 0.37700207, 0.34093142, 0.51861576, 0.58792891, 0.66384689, 0.70536104, 0.58621347, 0.74074098, 0.43232547, 0.29557632, 0.19852622, 0.45395502, 0.54480025, 0.65579231, 0.73106225, 0.40127790, 0.78839435, 0.61155256, 0.84766757, 0.71691014, 0.80962263, 0.45213885, 0.25293031, 0.27050711, 0.40409476, 0.14266665, 0.48446265, 0.09051555, 0.71223352, 0.79345829, 0.35288771, 0.88148154, 0.10363419, 0.79884387, 0.36022775, 0.12510236, 0.19056711, 0.55539650, 0.66090747, 0.83256709, 0.57063229, 0.60689768, 0.20386555, 0.23518874, 0.21504781, 0.88328979, 0.29824064, 0.91853159, 0.91839024, 0.45151355, 0.21253356, 0.28338827, 0.36172648, 0.10336113, 0.44574057, 0.01883467, 0.71434281, 0.85479742, 0.93916812, 0.02780940, 0.85691925, 0.30969739, 0.77912164, 0.07409899, 0.18085732, 0.78224726, 0.94551713, 0.68931098, 0.86371807, 0.57403381, 0.14750073, 0.94691866, 0.33416687, 0.98116533, 0.98003173),

label = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66","67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83")

When I made the tree with no labels at all, then ran following code, and I could see what numeral label was associated with what coordinates.

set.seed(42) plot(heattreeplot) + geom_text(data = labels_var, aes(x = x, y = y, label = label), size = 4) Looks like this:

taxa_03_plot_numeric_labels_sm From here, I changed the labels in my tibble to taxon names (so, instead of "1" I had "Bacteria", etc.), and I had to tweak the positions a bit to make it look nicer, from my point of view. Note that I also did not label every internal node. Just "Bacteria", and then the tip taxa. So that made it a bit less arduous.

Then I saved this new tibble as "labels_var", and ran this code:

set.seed(42) plot(heattreeplot) + geom_text(data = labels_var, aes(x = x, y = y, label = label), size = 4, fontface = 3)

The fontface = 3 makes the labels italic.

zachary-foster commented 4 months ago

Thanks mcddna! It would be a good improvement to italicize node labels. A few people have asked for it. I will try to add it once I get a chance.