小伙伴发来这个文章中的图,想要实现类似的图,用变量给axis text上色,并生成legend:

![](https://guangchuangyu.github.io/blog_images/R/ggplot2/Screenshot 2017-07-04 14.10.55.png)

这个可以说ggplot2是不支持的,aes映射不会被应用于axis上,而theme也不支持aes映射,你只能自己手动搞个color vector传给theme来上色,但这无法生成legend。

我只能打开脑洞,legend借助于额外的图层来生成,但这个额外的图层又不是我们想要在图形上展示的,这又是个无米之炊,我能想到的就是让图层透明,实际有,但你看不到,当然这样自动生成的legend也会看不到,但legend可以后面再修改,于是这不支持的事情,就通过变通变得可能:

require(ggplot2)

set.seed(2017-07-04)
d <- data.frame(x = letters[1:5], y = rnorm(5), 
		group = sample(c("Control", "Treatment"), 5, replace=TRUE),
		type = sample(LETTERS[1:2], 5, replace=TRUE)
)

p <- ggplot(d, aes(x,y)) + 
	geom_col(aes(fill=group))

这个代码很好懂,画一个柱状图,按group上色。

Continue reading

Dear Dr. Guangchuang Yu, I write to you regarding a doubt concerning the enrichGO function from Clustalprofiler package. I have been used this package before, but now I’m using the same R script and I have an error message.

This is the command I use:

go.bp <- enrichGO(gene = gene.df$ENSEMBL, universe = universe.ENSEMBLID, keytype = ‘ENSEMBL’, OrgDb = org.Ce.eg.db, ont = ‘BP’, pAdjustMethod = ‘BH’, pvalueCutoff = 0.01, qvalueCutoff = 0.05, readable=T)

and the error is the following one:

No gene set have size > 10 … –> return NULL…

My input list is attached to this email (101 genes in total). When I use this list in a web resource such as GOrilla it gives to me the proper GO terms.

Thank you very much in advance. Best regards,

María

最近clusterProfiler用户的问题,这个问题还蛮普遍。这个我在《why clusterProfiler fails》中也有谈到,并不是能出结果就是好的。没有结果也是一种结果。

Continue reading

群众纷纷表示图二是Excel画的,我觉得也是!Excel是生物学家的最爱啊。虽然做生信的人都看不上,最主要是没有记录,不具备可重复性。但现实就是大家都爱Excel。

Continue reading

ko数据库ID转换

Since the clusterProfiler is a very useful tools for GO and Kegg annotation.At present I want to use it to enrich for kegg result while only have the KO number ,So I want to convert the KO number to the pathway function,Is there have any function or methods in the software can convert it?any help will be appreciated

这个问题问说他想转KO到通路,首先这是一个常见的错误,很多人分不清Kko,所以在我告诉他可以把K number转成ko pathway的时候,我先指出他的错误。

ko is actually pathway map. I think you are talking about K number mapping to ko pathway.

> bitr_kegg("K00844", "kegg", "Path", "ko")
     kegg    Path
1  K00844 ko00010
2  K00844 ko00051
3  K00844 ko00052
4  K00844 ko00500
5  K00844 ko00520
6  K00844 ko00521
7  K00844 ko00524
8  K00844 ko01100
9  K00844 ko01110
10 K00844 ko01120
11 K00844 ko01130
12 K00844 ko01200
13 K00844 ko04066
14 K00844 ko04910
15 K00844 ko04930
16 K00844 ko04973
17 K00844 ko05230

Continue reading

Author's picture

Guangchuang Yu

Bioinformatics Professor @ SMU

Bioinformatics Professor

Guangzhou