Add metadata based on tree structure
Entering edit mode
23 months ago
Jack ▴ 50


I just started working with ggtree to visualise phylogenetic trees and so far it works very well.

Now I would like to add some meta data (tab-, csv- or excel-file) based on tree structure.

Ideally it would look similiar to this example: enter image description here

But instead of the SNP and Trait data, I would like to use simple text (tab-, csv- or excel-file).

[Tree//header] [metadata1//header] [metadata2//header] [...//header]

ID1 MetadataForID1 moreMetadataForID1 ...

Is there maybe a simple way to add this kind of data?

Thank you!

R ggtree • 2.0k views
Entering edit mode

Thank you for your answers!

With the help of the following code I am able to add meta data, that is saved in a .txt-file ('d1'):

ggtree(tree) %<+% d1 + geom_tiplab() + geom_tiplab(aes(label = factor(sample)), offset=0.1) + theme_tree2() + geom_tiplab(aes(label = factor(metadata)), offset=0.4) + xlim(NA, 4)

enter image description here

After aligning the data, I can not remove the lines:

ggtree(tree) %<+% d1 + geom_tiplab(align=TRUE, linesize=.5) + geom_tiplab(aes(label = factor(sample)), offset=0.1, align=TRUE) + theme_tree2() + geom_tiplab(aes(label = factor(metadata)), offset=0.4, align=TRUE) + xlim(NA, 4)

enter image description here

Is there a way to remove the lines for 'sample' and 'metadata'? And is it possible to add a header with a grey background, just like the one in my first post, for 'Sample' and 'metadata'?

Entering edit mode
23 months ago
Guangchuang Yu ★ 2.5k

The first column should be node numbers or labels for ggtree to link your data to the tree.

Please refer to our paper, There are a number of examples in the supplemental file.

Entering edit mode
23 months ago
thackl ★ 2.8k

If you are interested in some flexibility beyond ggtree's nice built-in functions, check out my blog post about an alternative approach:

Entering edit mode

Thanks for the links!

But unfortunately I could not find any example with plain text.

All the examples use only geom_tiplab() for text and add data to that. So for example SNP or trait data, matrix, sequence alignment, plot, ... I could not find any example with two or three columns of text

So, all I have is a text file, that looks like this:

label sample metadata

t1 Sample_1 metadata_1

t2 Sample_2 metadata_2

t3 Sample_3 metadata_3

t4 Sample_4 metadata_4

t5 Sample_5 metadata_5

No data and no x values.

So right now I have no clue how to realise this.

Thats why I painted a picture of the output, that I would like to achieve: enter image description here

Has anyone an idea, how to implement this?


Login before adding your answer.

Traffic: 1865 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6