how to color specific node or gene symbol from cnetplot ?
2
0
Entering edit mode
adR ▴ 40
@do-it-23093
Last seen 3 months ago
Germany, München

Dear all here, just wondering how to color specific node or gene symbol from cnetplot?

library(DOSE)
library(enrichplot)
library(clusterProfiler)
data(geneList)
deg <- names(geneList)[abs(geneList) > 2]
enrichment.result <- enrichDGN(deg)
edox <- setReadable(enrichment.result, "org.Hs.eg.db", "ENTREZID")
cnt_enrichment <- enrichplot::cnetplot(edox)

Now in the plot I would like to color the node or the gene symbol itself of the following MARCO, GZMB, CXCL11, CXCL10 LAG3, CCL8 as red and PDK1, GABRP, MELK and CENPE as blue.

I would appreciate it if someone could show me how to do it. Thanks ADR

clusterProfiler enrichplot cnetplot GuangchuangYu • 4.1k views
ADD COMMENT
3
Entering edit mode
@james-w-macdonald-5106
Last seen 5 hours ago
United States

I think you should be able to specify that with the 'color_gene' argument, but I can't figure out how one might do that. Failing to accomplish it that way, there is always the 'hack at it until you get what you want'.

## extract the data object from the ggplot object
dat <- cnt_enrichment$data
## change the colors
dat$color[dat$name %in% c("MARCO", "GZMB", "CXCL11", "CXCL10", "LAG3", "CCL8")] <- "#FF0000"
dat$color[dat$name %in% c("PDK1", "GABRP", "MELK", "CENPE")] <- "#0000FF"
## stuff it back in there
cnt_enrichment$data <- dat
## check it out
cnt_enrichment
ADD COMMENT
0
Entering edit mode

@james-w-macdonald-5106, this is brilliant. Thank you so much!!

ADD REPLY
0
Entering edit mode

Hi, thanks a lot for you reply. I have the same issue than adR but when I applied your solution, I see the changes in term of color in the ggplot object (obj$data$color) but when I would like to print the ggplot object ("check it out" part) in the graphic devise of RStudio, I see no changes.

ADD REPLY
0
Entering edit mode

You might want to ensure that you are actually printing the fixed object. I don't use RStudio, so have no idea if x11 has any effect, but if I wanted to check it, I would instanciate another graphics device and print again. Since it worked for both me and adR, my prior would be that you made a mistake somewhere. But without seeing the code you used it's all conjecture on my part.

ADD REPLY
0
Entering edit mode
Guangchuang Yu ★ 1.2k
@guangchuang-yu-5419
Last seen 27 days ago
China/Guangzhou/Southern Medical Univer…

Here is the answer:

foldChange = c(rep(1, 6), rep(-1, 4))
names(foldChange) <- c("MARCO", "GZMB", "CXCL11", "CXCL10", 
                "LAG3", "CCL8", "PDK1", "GABRP", "MELK", "CENPE")
p <- cnetplot(edox, foldChange=foldChange)
  1. you may want to disable the legend, then:
p <- cnetplot(edox, foldChange=foldChange) + guides(color='none')
  1. you may want to add a legend for the color you specify:
d = data.frame(type=c('upregulated', 'downregulated'), x=0, y=0)
p + geom_point(aes(alpha=type, x=x, y=y), data=d, shape=16, size=0)  + 
    guides(alpha=guide_legend(
                    override.aes=list(color=c("blue", "red"), 
                                    alpha=1, 
                                    size=3)
                            )
            )
ADD COMMENT

Login before adding your answer.

Traffic: 681 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