enrichplot
enrichplot copied to clipboard
change edge color in cnetplot
Dear Yu group, I use cnetplot function and set the parameter 'colorEdge' as TRUE. But I would like to set my own colors of edge instead of the default color, how can I do that?
I realize that you have posted this a while ago,... Yet, for the archive:
With the current version of enrichplot you will need to use the argument color_edge, and provide the name (or hex code) of the color (default is: color_edge = "grey").
See ?cnetplot.
> library(clusterProfiler)
>
> ## load example data
> data(geneList, package = "DOSE")
> de <- names(geneList)[1:100]
>
> ## default analysis
> y1 <- enrichGO(de, 'org.Hs.eg.db',
+ ont = "CC",
+ pvalueCutoff = 0.05,
+ pAdjustMethod = "BH",
+ qvalueCutoff = 0.2)
> p1 <- cnetplot(y1, color_edge = "red", showCategory = 5)
> print(p1)
>
In a previus version I used to be able to color the edges by pathway and also have them show up in the legend. Has this been removed?
No, but you will need to set the argument color_edge to category (instead of the name of a color).
p2 <- cnetplot(y1, color_edge = "category", showCategory = 5)
print(p2)
Thanks! This is exactly what I needed.
I am using v1.26.2, but color_edge = "category" doesn't work.
cnetplot(GOfile, node_label="all",showCategory=CatGO,categorySize="NES", categorySize="pvalue",foldChange = gene_list,circular = FALSE,color_edge = "category") +
- scale_colour_gradient2(name = "fold change", low = "blue", mid = "yellow", high = "red")
Scale for colour is already present.
Adding another scale for colour, which will replace the existing scale.
Error:
! Problem while converting geom to grob.
ℹ Error occurred in the 1st layer.
Caused by error:
! Unknown colour name: category
Run
rlang::last_trace()to see where the error occurred.
This is a Gene Set Enrichment Analysis file, and I want to color the genes and edges. I can put the same color for all categories, but I want to use different colors for different categories. I am not sure how to do it in the new version.
Could you upload an example network (from a previous analysis [that apparently worked]) to show what you are after?
Got some time to prepare some examples. See also these threads: https://github.com/YuLab-SMU/enrichplot/issues/302#issuecomment-2517971618 and https://github.com/YuLab-SMU/enrichplot/issues/293#issuecomment-2462502566
> ## load libraries
> library(clusterProfiler)
> library(enrichplot)
> library(org.Hs.eg.db)
>
> ## load example data
> data(geneList, package="DOSE")
>
> ## reproducible example
> res <- gseGO(geneList = geneList,
+ OrgDb = org.Hs.eg.db,
+ keyType = "ENTREZID",
+ ont = "CC",
+ minGSSize = 15,
+ maxGSSize = 100,
+ eps = 0,
+ pvalueCutoff = 0.05,
+ pAdjustMethod = "BH")
using 'fgsea' for GSEA analysis, please cite Korotkevich et al (2019).
preparing geneSet collections...
GSEA analysis...
leading edge analysis...
done...
>
> res <- pairwise_termsim(res)
> res <- setReadable(res, OrgDb = org.Hs.eg.db, keyType="ENTREZID")
>
>
>
> ## select 5 *specific* sets to be plotted
> sets2plot <- as.data.frame(res)[c(1,3,4,7,8),]$Description
> sets2plot
[1] "spindle midzone" "spindle microtubule"
[3] "outer kinetochore" "kinesin complex"
[5] "complex of collagen trimers"
>
> ## create cnetplot without node labels.
> ## these labels will be manually added
> ## using the function 'geom_cnet_label'
>
> ## note: only the 5 sets in sets2plot are displayed
> p1 <- cnetplot(res, showCategory=sets2plot, node_label = "none", color_edge = "category", foldChange = geneList)
> print(p1)
>
> ## add labels genes
> p2 <- p1 +
+ ggtangle::geom_cnet_label(node_label = "item", size = 2, fontface = "italic", color = "pink")
> print(p2)
>
> ## add labels categories
> p3 <- p2 +
+ ggtangle::geom_cnet_label(node_label = "category", size = 6, fontface = "bold", color = "green")
> print(p3)
>
> ## alternatively, plot the top 10 sets,
> ## but only label those sets present in sets2plot
> p4 <- cnetplot(res, showCategory=10, node_label = "none", color_edge = "category", foldChange = geneList)
> print(p4)
>
> p5 <- p4 +
+ ggtangle::geom_cnet_label(node_label = "item", size = 2, fontface = "italic", color = "gray")
> print(p5)
>
> p6 <- p5 +
+ ggtangle::geom_cnet_label(node_label = sets2plot, size = 3, fontface = "bold", color = "blue")
> print(p6)
>
> packageVersion("clusterProfiler")
[1] ‘4.14.6’
> packageVersion("enrichplot")
[1] ‘1.26.6’
> R.Version()$version.string
[1] "R version 4.4.2 (2024-10-31 ucrt)"
> BiocManager::version()
[1] ‘3.20’
>
How do we control the edge aesthetic when coloured by category? I would like to change the edge colours from the ggplot default and also rename 'category' in the legend. I tried scale_colour_manual and ggraph::scale_edge_colour_manual to no effect. Thank you