ggtree with funny fonts
[This article was first published on YGC » R, 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.
showtext is a neat solution to use various types of fonts in R graphs and make it easy to use funny fonts.
With showtext, we can draw phylogenetic tree with different types of fonts even with symbolic/icon fonts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | require(showtext) font.add.google("Gochi Hand", "gochi") font.add.google("Rock Salt", "rock") link = "http://img.dafont.com/dl/?f=wm_people_1"; download.file(link, "wmpeople1.zip", mode = "wb"); unzip("wmpeople1.zip"); font.add("wmpeople1", "wmpeople1.TTF"); link = "http://img.dafont.com/dl/?f=emoticons"; download.file(link, "emoticons.zip", mode = "wb"); unzip("emoticons.zip"); font.add("emoticons", "emoticons.ttf"); showtext.auto() set.seed(2015-05-14) library(ggplot2) library(ggtree) tree <- rtree(30) ggtree(tree, color="darkgreen") + geom_tiplab(family="gochi") + theme_classic() + theme(axis.text.x=element_text(size=rel(4), family="emoticons", color="firebrick")) + scale_y_continuous(breaks=seq(0, 30, 4), labels=letters[c(12:17, 20, 21)]) + theme(axis.text.y=element_text(size=rel(4), family="wmpeople1", color="#FDAC4F")) + annotate("text", x=2, y=18, label="Have fun with ggtree!", family="rock", angle=30, size=12, color="steelblue") |
1 2 3 4 | download.file("http://dl.dafont.com/dl/?f=people_freak", "people_freak.zip", mode="wb") unzip("people_freak.zip") font.add("people_freak", "People_freak.ttf") ggtree(rtree(10)) + geom_text(aes(label=node, color=isTip), family="people_freak", hjust=0) |
Related Posts
To leave a comment for the author, please follow the link and comment on their blog: YGC » R.
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.