Home > Enterprise >  Show the Volcano plot points with colour above the others in background with ggplot2 R
Show the Volcano plot points with colour above the others in background with ggplot2 R

Time:10-28

I have written the code below to create a volcano plot, which is colored based on the variable "group", of the data.frame "gseaRes". The colored points refer to pathways I 'm interested in, and the others(not of interest) should be in grey, in the background. I used the parameter "alpha" in geom_point to make it more transparent, but the colored points are always blurred inside the grey points, and the grey points are getting hardly seen, so we loose information of how many they are. I was wandering if sb knows how to plot these points in two layers ,one over the other,like we do with scatterplots and lines on the top. Is there a parameter, or another way of coding it ? enter image description here

Here is the dataset I used: https://github.com/mariakondili/GSEA/blob/main/GSEA_dataframe.tsv

Here is how I produced it :

suppressPackageStartupMessages(library(tidyverse)) 

gseaRes %>%  
mutate("group" = ifelse(str_detect(pathway,"blabla1"),"group1",
                                    ifelse(str_detect(pathway,"blabla2"), "group2",   
                                    ifelse(str_detect(pathway,"blabla3"), "group3",
                                    ifelse(str_detect(pathway,"blabla4"), "group4",
                                    ifelse(str_detect(pathway,"blabla5"),"group5","Other"))))))



ggplot(gseaRes , aes(x=-log10(padj), y=NES, size=size, col=group))  
geom_point(alpha=ifelse(gseaRes$group=="Other",0.02, 1))  
scale_color_manual(values = c("group1" = "violetred",
                              "group2" = "royalblue1" ,
                              "group3"="orange", 
                               "group4" = "cyan",
                               "group5" ="tomato4",
                               "Other" = "grey30"))   theme_classic()



CodePudding user response:

You could use two geom_point to which you pass filtered datasets, one containing only the "Other" category, one containing the pathways you are interested in:

library(tidyverse)

gseaRes <- read_tsv("https://raw.githubusercontent.com/mariakondili/GSEA/main/GSEA_dataframe.tsv")

gseaRes <- gseaRes %>%
  mutate(group = ifelse(str_detect(pathway, "_ACTIN"), "group1",
    ifelse(str_detect(pathway, "blabla"), "group2",
      ifelse(str_detect(pathway, "blabla"), "group3",
        ifelse(str_detect(pathway, "blabla"), "group4",
          ifelse(str_detect(pathway, "blabla"), "group5", "Other")
        )
      )
    )
  ))

ggplot(gseaRes, aes(x = -log10(padj), y = NES, size = size, col = group))  
  geom_point(data = filter(gseaRes, group == "Other"), alpha = .02)  
  geom_point(data = filter(gseaRes, !group == "Other"))  
  scale_color_manual(values = c(
    "group1" = "violetred",
    "group2" = "royalblue1",
    "group3" = "orange",
    "group4" = "cyan",
    "group5" = "tomato4",
    "Other" = "grey30"
  ))  
  theme_classic()

  • Related