[This article was first published on R on Guangchuang YU, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
With ggtree (Yu et al. 2017), it is very easy to create phylomoji. Emoji is internally supported by ggtree.
Use emoji in taxa labels
library(ggtree)
tree_text <- "(((((cow, (whale, dolphin)), (pig2, boar)), camel), fish), seedling);"
x <- read.tree(text=tree_text)
ggtree(x, linetype="dashed", color='firebrick') +
xlim(NA, 7) + ylim(NA, 8.5) +
geom_tiplab(aes(color=label), parse='emoji', size=14, vjust=0.25) +
labs(title="phylomoji", caption="powered by ggtree + emoji")
p <- ggtree(x, layout='circular') +
geom_tiplab2(aes(color=label), parse='emoji', size=12, vjust=0.25)
print(p)
open_tree(p, angle=200)
open_tree(p, angle=60) %>% rotate_tree(-75)
Labeling clades using emoji
set.seed(123)
tr <- rtree(30)
ggtree(tr) + xlim(NA, 5) +
geom_cladelabel(node=41, label="chicken", parse="emoji",
size=12, align=TRUE, color="firebrick") +
geom_cladelabel(node=51, label="duck", parse="emoji",
size=12, align=TRUE, color="steelblue") +
geom_cladelabel(node=32, label="family", parse="emoji",
size=12, align=TRUE, color="darkkhaki")
Apple Color Emoji
Although R’s graphical devices don’t support AppleColorEmoji , it’s still possible to use it. We can export the plot to svg file and render it in Safari.
library(ggimage)
library(gridSVG)
p <- ggtree(x, size=2) + geom_tiplab(size=20, parse='emoji') +
xlim(NA, 7) + ylim(NA, 8.5) +
geom_phylopic(image="79ad5f09-cf21-4c89-8e7d-0c82a00ce728",
color="firebrick", alpha = .3, size=Inf)
p
ps = grid.export("emoji.svg", addClass=T)
Further reading
Please visit ggtree homepage, https://guangchuangyu.github.io/ggtree, to find out more.
References
Yu, Guangchuang, David Smith, Huachen Zhu, Yi Guan, and Tommy Tsan-Yuk Lam. 2017. “Ggtree: An R Package for Visualization and Annotation of Phylogenetic Trees with Their Covariates and Other Associated Data.” Methods in Ecology and Evolution 8 (1): 28–36. doi:10.1111⁄2041-210X.12628.
To leave a comment for the author, please follow the link and comment on their blog: R on Guangchuang YU.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
