enrichplot
enrichplot copied to clipboard
Dotplot of compareCluster enrichGO ALL ontology [fixing & enhancement]
This is for https://github.com/YuLab-SMU/clusterProfiler/issues/482
When fortify compareClusterResult that frome enrichGO()
and ontology = "all"
, the cluster of data is wrong assigned. And this should be a bug.
I, therefore, fixed this bug,
if (class(result$GeneRatio) == "character" && grep("/", result$GeneRatio[1])) {
gsize <- as.numeric(sub("/\\d+$", "", as.character(result$GeneRatio)))
gcsize <- as.numeric(sub("^\\d+/", "", as.character(result$GeneRatio)))
result$GeneRatio <- gsize/gcsize
if (("ONTOLOGY" %in% colnames(result)) && (length(unique(result$ONTOLOGY)) > 1)){
# do nothing
} else {
cluster <- paste(as.character(result$Cluster),"\n", "(", gcsize, ")",
sep="")
lv <- unique(cluster)[order(as.numeric(unique(result$Cluster)))]
result$Cluster <- factor(cluster, levels = lv)
}
}
and further adjust the corresponding dotplot
method to plot a satisfactory figure.
# show multiply GO enrichment result in separate panels
if ("ONTOLOGY" %in% colnames(df) && length(unique(df$ONTOLOGY)) > 1){
p = p + facet_grid(
ONTOLOGY ~ .,
scales = "free",
space = "free"
)
}
While run the following example.
data(geneList, package="DOSE")
mydf <- data.frame(Entrez=names(geneList), FC=geneList)
mydf <- mydf[abs(mydf$FC) > 1,]
mydf$group <- "upregulated"
mydf$group[mydf$FC < 0] <- "downregulated"
mydf$othergroup <- "A"
mydf$othergroup[abs(mydf$FC) > 2] <- "B"
library(org.Hs.eg.db)
formula_res <- compareCluster(Entrez~group+othergroup, data=mydf, fun="enrichGO", OrgDb = org.Hs.eg.db, ont = "ALL")
dotplot(formula_res, label_format = 60)
It will give:
春晖哥,我觉得您对fortify.compareClusterResult
的处理方式很不错。
p = p + facet_grid(
ONTOLOGY ~ .,
scales = "free",
space = "free"
)
这一句是否有必要?我感觉把是否分面由用户自行处理比较合适。
春晖哥,我觉得您对
fortify.compareClusterResult
的处理方式很不错。p = p + facet_grid( ONTOLOGY ~ ., scales = "free", space = "free" )
这一句是否有必要?我感觉把是否分面由用户自行处理比较合适。
从设计理念上讲,去掉比较合适;从对用户友好上讲,留着也未尝不可。请老板 @GuangchuangYu 定夺吧。
I also met the bug when I did compareCluster fun = enrichGO ont = "ALL", and I have read the code for the bug, but I have some trouble to apply it myself. Could you explain how to fix it in detail? Should I modify the R Package or create an R script?
I also met the bug when I did compareCluster fun = enrichGO ont = "ALL", and I have read the code for the bug, but I have some trouble to apply it myself. Could you explain how to fix it in detail? Should I modify the R Package or create an R script?
I solved this problem by replacing the dotplot.R and mothed-fortify.R files in enrichplot-master.zip and installing enrichplot package in again. Thanks for your code!
FYI, I will comment out the facet code.