Visualize tree with associated matrix

The gheatmap function is designed to visualize phylogenetic tree with heatmap of associated matrix.

In the following example, we visualized a tree of H3 influenza viruses with their associated genotype.

The width parameter is to control the width of the heatmap. It supports another parameter offset for controlling the distance between the tree and the heatmap, for instance to allocate space for tip labels.

For time-scaled tree, as in this example, it’s more often to use x axis by using theme_tree2. But with this solution, the heatmap is just another layer and will change the x axis. To overcome this issue, we implemented scale_x_ggtree to set the x axis more reasonable.

Visualize tree with multiple sequence alignment

With msaplot function, user can visualize multiple sequence alignment with phylogenetic tree, as demonstrated below:

A specific slice of the alignment can also be displayed by specific window parameter.

Annotate a phylogenetic tree with insets

ggtree provides a function, inset, for adding subplots to a phylogenetic tree. The input is a tree graphic object and a named list of ggplot graphic objects (can be any kind of charts), these objects should named by node numbers. To facilitate adding bar and pie charts (e.g. summarized stats of results from ancestral reconstruction) to phylogenetic tree, ggtree provides nodepie and nodebar functions to create a list of pie or bar charts.

Annotate with bar charts

The sizes of the insets can be ajusted by the paramter width and height.

Users can set the color via the parameter color. The x position can be one of ‘node’ or ‘branch’ and can be adjusted by the parameter hjust and vjust for horizontal and vertical adjustment respecitvely.

Annotate with pie charts

Similarly, users can use nodepie function to generate a list of pie charts and place these charts to annotate corresponding nodes. Both nodebar and nodepie accepts parameter alpha to allow transparency.

Annotate with other types of charts

The inset function accepts a list of ggplot graphic objects and these input objects are not restricted to pie or bar charts. They can be any kinds of charts and hybrid of these charts.

After annotating with insets, users can further annotate the tree with another layer of insets.

Annotate with image files

Plot tree with associated data

For associating phylogenetic tree with different type of plot produced by user’s data, ggtree provides facet_plot function which accepts an input data.frame and a geom function to draw the input data. The data will be displayed in an additional panel of the plot.

Tree annotation with Phylopic

PhyloPic is a database that stores reusable silhouette images of organisms. ggtree supports downloading images from PhyloPic and annotating phylogenetic tree with the downloaded images.