Clipping of long geom labels

181 views
Skip to first unread message

Håkon Kaspersen

unread,
Dec 17, 2020, 6:56:28 AM12/17/20
to ggtree
Hello!
I am trying to figure out if it is possible to atumatically prevent clipping of long labels when using geom_tiplab. I am trying to implement ggtree in automatic generation of basic trees, and the issue is that the labels are outside the plot area, as you can see in the tree below. I know i can fix this with xlim(), but since I want this to work with several different datasets its impossible to know the range of the x-axis in this case. Is there a way to prevent it from clipping?

Here is the code:

tree <- structure(list(edge = structure(c(13L, 13L, 14L, 15L, 16L, 17L, 
18L, 19L, 19L, 18L, 17L, 16L, 15L, 20L, 21L, 21L, 20L, 14L, 22L, 
22L, 13L, 1L, 14L, 15L, 16L, 17L, 18L, 19L, 2L, 3L, 4L, 5L, 6L, 
20L, 21L, 7L, 8L, 9L, 22L, 10L, 11L, 12L), .Dim = c(21L, 2L)), 
    edge.length = c(0.0454027514, 0.0069436325, 0.0052847563, 
    0.007239064, 0.0142035283, 0.0298516829, 0.0002808764, 0.0001813847, 
    0.000251533, 0.0003989615, 0.0296560401, 0.0434632726, 0.0272796306, 
    0.0107160042, 0.0484294709, 0.0499746076, 0.0512355246, 0.0062195387, 
    0.0471805883, 0.0464889512, 0.045640451), Nnode = 10L, node.label = c("", 
    "53", "100", "100", "100", "100", "100", "100", "100", "53"
    ), tip.label = c("HFGJVBBXY_147-79PK_ACCATTAA-ACCGGTTC_assembly.fasta.ref", 
    "KGVETS-2019-01-2303_assembly.fasta", "HFGJVBBXY_49-23PK_CTACGAAG-CTGTCGAG_assembly.fasta", 
    "KGVETS-2019-01-2950_assembly.fasta", "HFGJVBBXY_221-138PK_TCCAGGTA-ACTGGAGC_assembly.fasta", 
    "HFGJVBBXY_144-78PK_GGTGTCCG-AGACGCTG_assembly.fasta", "HFGJVBBXY_206-117PK_TCTCCGTG-ACGATTCA_assembly.fasta", 
    "HFGJVBBXY_164-86PK_TTAGGTTG-CAATCGTC_assembly.fasta", "HFGJVBBXY_231-143PK_AGTTCCGT-ACGCGGCC_assembly.fasta", 
    "HFGJVBBXY_229-141PK_AGGTCAAG-ATAACGCG_assembly.fasta", "HFGJVBBXY_44-21PK_TCGAAGCT-CTCAGTGC_assembly.fasta", 
    "HFGJVBBXY_211-122PK_ACAATGCC-TAAGGACG_assembly.fasta")), class = "phylo", order = "cladewise")

ggtree(tree) +
  geom_tiplab()


smalltree.png

Yu, Guangchuang

unread,
Dec 22, 2020, 1:47:28 AM12/22/20
to Håkon Kaspersen, ggtree

--
1. G Yu*. Using ggtree to visualize data on tree-like structures. Current Protocols in Bioinformatics. 2020, 69:e96. https://doi.org/10.1002/cpbi.96
2. LG Wang, TTY Lam, S Xu, Z Dai, L Zhou, T Feng, P Guo, CW Dunn, BR Jones, T Bradley, H Zhu, Y Guan, Y Jiang, G Yu*. treeio: an R package for phylogenetic tree input and output with richly annotated and associated data. Molecular Biology and Evolution. 2020, 37(2):599-603. http://dx.doi.org/10.1093/molbev/msz240
3. G Yu*, TTY Lam, H Zhu, Y Guan*. Two methods for mapping and visualizing associated data on phylogeny using ggtree. Molecular Biology and Evolution, 2018, 35(2):3041-3043. https://doi.org/10.1093/molbev/msy194
4. G Yu, DK Smith, H Zhu, Y Guan, TTY Lam*. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data, Methods in Ecology and Evolution, 2017, 8(1):28-36. https://doi.org/10.1111/2041-210X.12628
5. Book: https://yulab-smu.top/treedata-book/
---
You received this message because you are subscribed to the Google Groups "ggtree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/75b61c33-89bb-4ef3-883e-5b32211bb104n%40googlegroups.com.


--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu PhD
Professor, Associate Director
Department of Bioinformatics
School of Basic Medical Sciences
Southern Medical University
Guangzhou, China
-~----------~----~----~----~------~----~------~--~---
Reply all
Reply to author
Forward
0 new messages