Changing barplot color on enrichment-based data
1
1
Entering edit mode
5 months ago
Gerard ▴ 10

Hello,

I ran a enrichment analysis using clusterprofiler, like this :

upregulated_enrich <- enrichGO(
  gene         = rownames(upregulated_genes),
  OrgDb        = org.Hs.eg.db,
  keyType      = "SYMBOL",
  ont          = "BP",
  pAdjustMethod = "BH",
  pvalueCutoff = 0.05,
  qvalueCutoff = 0.05
)

Then I made a bar plot out of the result:

barplot(upregulated_enrich, x = "Count", color = "p.adjust", showCategory = 15, font.size = 10, cex.names = 1.5)

The problem is, the color is a gradient going from red to blue, and I would like it to be in grey.

I tried several things, as I understood barplot made a ggplot object I tried to add scale_color_gradient but it doesn't work. I also tried to add the argument col = c("black", "grey") to the barplot function but it does not change the color.

Can anybody help ? Thank you in advance

ggplot2 • 602 views
ADD COMMENT
0
Entering edit mode

As an update, I tried to do the plot directly through ggplot, like this :

ggplot(upregulated_enrich_df, aes(x=Description, y=Count, fill = p.adjust)) + 
    geom_bar(stat = "identity") +
    coord_flip()

But I get the following error :

Continuous values supplied to discrete scale. Example values: 2.06704461473967e-28, 8.9145806694221e-27, 2.01985496772942e-26, 9.43537110094994e-21, and 1.45468202900121e-20

I'm trying to color the bars of the plot according to the adjusted p-value, but it's a continuous coloring and not a discrete one, any way to fix this ?

Many thanks

ADD REPLY
0
Entering edit mode
5 months ago
Hamtaro ▴ 50

Did you try scale_fill_gradient?

barplot_object <- barplot(upregulated_enrich, x = "Count", color = "p.adjust", showCategory = 15, font.size = 10, cex.names = 1.5)

# Adjusting the color to be in grey scale
barplot_object + scale_fill_gradient(low = "black", high = "grey")
ADD COMMENT
0
Entering edit mode
## scale_fill_gradient worked for me, though the gradient is limited, for me it only showed 3 colors

fit <- plot(barplot(GO_results_BP,showCategory = 10)+ scale_fill_gradient(low = "black", high = "lightgrey")) 

## Another related option is scale_fill_gradientn, then you can set a specific palette

fit <- plot(barplot(GO_results_BP,showCategory = 10)+ scale_fill_gradientn(colours = gray.colors(10))) 
ADD REPLY

Login before adding your answer.

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