最近看一个画图的公众号,基本上通篇是代码,最后上个图,我觉得作者就只想表达「哇,我好牛逼」,读者看完可能也只是发出一句「好牛逼」,然后就没有然后了。且不说他读的数据是他电脑上的,你拿了代码也不好重复,最主要是代码死长,缺少解释!

我的写作风格则不一样,一篇文章我一般只会讲解一个点,力图讲清楚,让别人看明白。比如bootstrap分段标记这一篇,代码足够短且简单,但我还是分模块来讲,一行画树,一行做bootstrap分段标记,最后一行修图,虽然三行,但按功能分开,再加上文字解释,读懂是必须的。再比如纯代码生成banner​也是分成加载中文字体、读图、图上嵌图三块。即使简单的代码,也要分模块配以文字解析。

我每次只讲解一个点,但有些知识点是关联的,所以有可能会有断片的情况出现,比如之前写phylomoji,就有同学表示没看懂,这个用到了ggtree和emojifont,两个包我都写过很多文介绍,所以在写phylomoji时都没有介绍,如果没看过以前文章的人,可能就不清楚了。所以呢,适当的时候,汇总一下,是很有必要的。

emojifont包我基本上都介绍完了,如果你能通读这几篇文章,那么你必然能够用emoji来作图装逼,能够用emoji来娱乐自己,就像我用emoji给自己快乐一样!

Continue reading

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 + emojifont")

Continue reading

虽然我不喜欢DAVID,但很多用户喜欢,所以clusterProfiler也支持了,最近github上又有人要求支持自定义背景

Dear Guangchuang,

I am using clusterProfiler in Kegg pathway enrichment analysis, it is useful and nice. I am looking for a function which accept background and has ability to deal with Ensembl gene ID.

In a function enrichDAVID it can takes ensembl gene id as an input format, but not allows to enter background. enrichDAVID(gene = gene, idType="ENSEMBL_GENE_ID", annotation="KEGG_PATHWAY", species= "hsa")

Other command enrichKEGG has a background input but only takes entrez gene id, enrichKEGG(gene, organism = "hsa", keyType = "kegg", universe)

I have tried to convert my ensembl gene IDs to entrez gene id, but some ensembl gene IDs represent more than one entrez gene ID. I downloaded KEGG pathway dataset to apply fisher exact test. however, genes are in entrez ID and i am still dont know how to convert.

Continue reading

想要分段标记bootstrap,比如0-70, 70-90, 90-100之类的。这个对于ggtree来说,太简单。

首先我们要读树,用treeioread.newick,它和read.tree的不同之处是,加入了参数node.label,当node.label存的不是label,而是bootstrap等数字型的时候,你可以传入node.label='support',这样它会把node label解析为support value,另存为树注释数据,而不是和tip label混在一起。label变量只能存为字符型,因为和tip label混了,而字符型会让数字操作稍微复杂点。所以我们要用read.newick

tree <- read.newick("RMI.phy_phyml_tree_rooted_labeled.txt", node.label='support')
root <- getRoot(tree@phylo)

p <- ggtree(tree, color="black", size=1.5, linetype=1,  ladderize=TRUE) + 
     ggtitle(label="Figure A") + 
    geom_tiplab(size=4.5, hjust = -0.060, fontface="bold") +  xlim(0, 0.09)

Continue reading

来自R的桌面提醒

notifier包实现了跨平台的桌面提醒功能,当然它是调用了外部的命令,比如windows使用了toaster,老版本windows使用的是notifu,在linux下使用notify-send,而在OSX下,则调用了terminal-notifier,通过了简单的封装之后,就可以给桌面发布消息提醒了。

比如:

library(notifier)
notify(
  title = "15 Packages out of date",
  msg = c("You can run update.packages() to update them.",
  "Outdated packages: Boom colorspace desc memuse networkD3",
  "pbapply revealjs rgl rmdformats timevis and 5 more")
)

​ 效果如下:

Continue reading

Author's picture

Guangchuang Yu

Bioinformatics Professor @ SMU

Bioinformatics Professor

Guangzhou