How to colour points in cnetplot of clustprofiler?
0
0
Entering edit mode
2.7 years ago
DN99 ▴ 20

I have a cnetplot from running enrichment with kegg using clusterprofiler. I have scores input as the fold change but for each gene in the plot they are not varying in colour to show their difference in the fold change score.

My dataset is genes of entrez IDs and then each gene has a score from 0.5-0.9 (instead of fold change) that I want to be able to see by colour code in the plot, is this possible or does the foldchange parameter only use fold change measures?

For example my data looks like this:

Gene   Score
1234    0.9
5678    0.83
91011  0.89

I am then coding to get the cnetplot with:

kegg_enrich <-  enrichKEGG(gene   = df$Gene,
                   organism     = 'hsa',
                   pvalueCutoff = 0.05,
                   pAdjustMethod = 'fdr')

kegg <- setReadable(kegg_enrich, 'org.Hs.eg.db', 'ENTREZID')
kegg_genes <- kegg[,]

gene_list_scores <- df$Scores
gene_list_scores<-na.omit(gene_list_scores)
gene_list_scores = sort(gene_list_scores, decreasing = TRUE)

gene_of_interest <- dplyr::filter(kegg_genes, grepl('PTK2', geneID))
gene_of_interest<- enrichDF2enrichResult(gene_of_interest)

options(ggrepel.max.overlaps = 1000)
pother <- cnetplot(gene_of_interest, foldChange=gene_list_scores)
pother + scale_color_gradientn(name = "Score", colours = c("blue", "red"))

I am expecting the foldChange=gene_list_scores to enable each gene in the plot to be coloured by their score in my data but the plot output looks like:

enter image description here

clusterprofiler cnetplot R • 2.4k views
ADD COMMENT
0
Entering edit mode

Probably you need to enable colorEdge = TRUE.

Follow this link for detailed syntax.

ADD REPLY
0
Entering edit mode

Thank you for this, using colorEdge = TRUE alone only makes the lines coloured for some reason, but trying out the code from the link adds a colour scale legend, although still doesn't colour each gene point in - but from this I can see new ways to try out to get the syntax to work, thank you for your help!

ADD REPLY
0
Entering edit mode

Hi, did you manage to figure this out? I am also stuck due to the same problem, would appreciate any help on figuring this out!

ADD REPLY
0
Entering edit mode

Hey guys! I think I may have an answer to your question. So to change the colour of the gene points, you need to supply a vector to foldChange. This vector needs to be a numeric vector named with the gene names. For example:

fold_change_geneList <- setNames(object = translated_genes[,"FoldChange"],nm = translated_genes[,"Gene"])
head(fold_change_geneList)
        A2M       ACADM       ACAT1       PSEN1        SGCA       AMPD1 
-0.01335785 -0.23941324 -0.15789244  0.08709648  0.13132283  0.21851109

Supply this vector to the function and you will get coloured gene nodes!

If you want to change the colours of the nodes, I know no intuitive way to do so, but during the summer of 2021 I found where the beige node colour is stored (see this link) and how to change it. This is how to change the colour in enrichplot v. 1.18.3:

cnetplot[["layers"]][[2]][["aes_params"]][["colour_new"]] <- "pink"

Hope this helps!

ADD REPLY

Login before adding your answer.

Traffic: 1511 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6