I extended the subview function to support embed image file in a ggplot object.

set.seed(123)
d = data.frame(x=rnorm(10), y=rnorm(10))

imgfile <- tempfile(, fileext=".png")
download.file("https://avatars1.githubusercontent.com/u/626539?v=3&u=e731426406dd3f45a73d96dd604bc45ae2e7c36f&s=140",
	          destfile=imgfile, mode='wb')

p = ggplot(d, aes(x, y))
subview(p, imgfile, x=d$x[1], y=d$y[1]) + geom_point(size=5)

In previous post, I have introduced using annotation_image function for annotating tips with local images.

Now with the updated subview function, we can use inset function to annotate nodes/tips with image files and/or subplots.

set.seed(2015-12-31)
tr <- rtree(15)
p <- ggtree(tr)

img <- list(imgfile, imgfile)
names(img) <- c("18", "22")
inset(p, img)

PS: As I got more and more emails from ggtree users, I created a forum, https://groups.google.com/forum/#!forum/bioc-ggtree. With this forum, ggtree users can help each others and also solutions posted in the forum can help other peoples when they google search their questions. Please join the forum and post your questions if you have any.

Citation

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. doi:10.1111/2041-210X.12628.