Annotating phylogenetic tree with images using ggtree and ggimage

February 28, 2018

(This article was first published on R on Guangchuang YU, and kindly contributed to R-bloggers)

With ggimage, we are able to plot images using grammar of graphics. The layers defined in ggimage can be directly applied to ggtree to annotate phylogenetic tree using local/online image files.

ggtree seamlessly work with ggimage. The geom_tiplab and geom_nodelab can accept parameter of geom="image" to parse taxa labels as image files and use them to “label” the taxa using images instead of text strings. Here are some examples for demonstration.

Annotate tips

url <- paste0("",
x <- read.tree(paste0(url, "tree_boots.nwk"))
info <- read.csv(paste0(url, "tip_data.csv"))
p <- ggtree(x) %<+% info + xlim(NA, 6)
p + geom_tiplab(aes(image= imageURL), geom="image", offset=2, align=T, size=.16, hjust=0) +
    geom_tiplab(geom="label", offset=1, hjust=.5)

Annotate internal nodes

## example from
tree <-"")
phylopic_info <- data.frame(node = c(124, 113, 110, 96, 89, 70),
                            phylopic = c("7fb9bea8-e758-4986-afb2-95a2c3bf983d",
                            species = c("galagoids", "lemurs", "tarsiers",
                                        "cebids", "hominoids", "cercopithecoids"))
pg <- ggtree(tree)
pg %<+% phylopic_info + geom_nodelab(aes(image=phylopic), geom="phylopic", alpha=.5, color='steelblue')

d <- data.frame(node = c("70","89","96","110","113","124"),
                images = c("",
pg %<+% d + geom_nodelab(aes(image=images), geom="image")

Use image as background

pg + geom_phylopic(image="79ad5f09-cf21-4c89-8e7d-0c82a00ce728", size=Inf, alpha=.5, color='firebrick')

Here is another example that uses Tabikaeru (known as traveling frog, a popular mobile game) image to decorate a phylogenetic tree of frog, see reproducible source code on

To leave a comment for the author, please follow the link and comment on their blog: R on Guangchuang YU. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)