查看原文
其他

reproducible logo generated by ggtree

2017-07-01 Y叔 biobabble

之前发表的文章《纯代码生成banner》介绍了用ggimage拼出个横幅,左边是本公众号的logo,右边是二维码,全部都是用R纯代码生成。

右边二维码用ggplot2画,写了个函数ggqrcode,结果被小伙伴抢先在公众号平台上发布,我的内心是这样子的:

今天就来讲讲左边的logo,这个完全是ggtree做出来的。一方面ggtree的环形树可以通过指定开口生扇子形,另一方面可以画中空的环形树

ggtree provides many helper functions for manupulating phylogenetic trees and make it easy to explore tree structure visually. Here, as examples, I used ggtree to draw capital character G and C, which are first letter of my name :-).


To draw a tree in such shape, we need fan layout (circular layout with open angle) and then rotating the tree to let the open space on the correct position. Here are the source codes to produce the G and C shapes of tree. I am thinking about using the G shaped tree as ggtree logo. Have fun with ggtree :-)

   library(ggtree)    beast_file <- system.file("examples/MCC_FluA_H3.tree", package="ggtree")    beast_tree <- read.beast(beast_file)    genotype_file <- system.file("examples/Genotype.txt", package="ggtree")    genotype <- read.table(genotype_file, sep="\t", stringsAsFactor=F)    p <- ggtree(beast_tree, layout='circular', color="#4DAF4A", size=2, branch.length='none', right=T) +        annotate('text', x=0, y=40, label='ggtree', family='mono', size=16)    p2 <- gheatmap(p, genotype, width=0.2, hjust='left', colnames_angle=-10, font.size=1.5)  +        scale_fill_manual(values=c("#E41A1C","#377EB8","#FC8D59")) + theme_tree()    open_tree(p2, 80) %>% rotate_tree(80)

   p <- ggtree(beast_tree, layout='circular', color="#4DAF4A",               size=2, branch.length='none', right=T) + xlim(-30, NA)    p2 <- gheatmap(p, genotype, width=0.2, hjust='left', colnames=F) +        scale_fill_manual(values=c("#E41A1C","#377EB8","#FC8D59")) + theme_tree()    open_tree(p2, 90) %>% rotate_tree(50)

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.


公众号的头像就是这么来的 , GC拼在一起可以用ggimage包,当然整个banner都是用ggimage拼的:)



赞赏

您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存