2
$\begingroup$

I have generated a volcano plot with a differential expression file.

Code for inputing file:

macrophage_list <- read.table("differential_expression_macrophage.csv", header = T, sep = ",")

library(tidyr)
final_df <- df %>% pivot_longer(., -c(Feature.ID, Feature.Name), names_to = c("set",".value"), names_pattern = "(.+)_(.+)")

# A tibble: 80 x 6
   Feature.ID Feature.Name set       Mean.Counts Log2.fold.change Adjusted.p.value
   <fct>      <fct>        <chr>           <dbl>            <dbl>            <dbl>
 1 a          A            Cluster.1    0.000961            0.292           1     
 2 a          A            Cluster.2    0.000902            0.793           1     
 3 a          A            Cluster.3    0.00181             1.46            0.758 
 4 a          A            Cluster.4    0.000642            0.269           1     
 5 b          B            Cluster.1    0.000320            1.95            0.910 
 6 b          B            Cluster.2    0.00180             4.77            0.154 
 7 b          B            Cluster.3    0                   2.19            1     
 8 b          B            Cluster.4    0                   1.66            1     
 9 c          C            Cluster.1    0.00128            -2.01            0.0467
10 c          C            Cluster.2    0.00632             0.352           1     
# … with 70 more rows

output of head(final_tumor)

# A tibble: 6 x 6
  Feature.ID        Feature.Name set       Mean.Counts Log2.fold.change Adjusted.p.value
  <fct>             <fct>        <chr>           <dbl>            <dbl>            <dbl>
1 ENSG00000227232.5 WASH7P       Cluster.1     0                   1.50            1    
2 ENSG00000227232.5 WASH7P       Cluster.2     0                   1.73            1    
3 ENSG00000227232.5 WASH7P       Cluster.3     0                   1.77            1    
4 ENSG00000227232.5 WASH7P       Cluster.4     0.00114             4.30            0.293
5 ENSG00000227232.5 WASH7P       Cluster.5     0                   2.15            1    
6 ENSG00000227232.5 WASH7P       Cluster.6     0                   1.22            1 

output of tail(final_tumor)

# A tibble: 6 x 6
  Feature.ID        Feature.Name set        Mean.Counts Log2.fold.change Adjusted.p.value
  <fct>             <fct>        <chr>            <dbl>            <dbl>            <dbl>
1 ENSG00000210196.2 MT-TP        Cluster.6       0.0699          -0.202           0.790  
2 ENSG00000210196.2 MT-TP        Cluster.7       0.0801           0.0386          1      
3 ENSG00000210196.2 MT-TP        Cluster.8       0.0711           0.0875          1      
4 ENSG00000210196.2 MT-TP        Cluster.9       0.0152          -2.31            0.00127
5 ENSG00000210196.2 MT-TP        Cluster.10      0.0147          -2.30            0.00612
6 ENSG00000210196.2 MT-TP        Cluster.11      0.122            0.762           1  

Code for generating volcano plot:

library(ggplot2)
library(ggrepel)
ggplot(final_tumor, aes(x = Log2.fold.change,y = -log10(Adjusted.p.value), label = Feature.Name))+ 
  geom_point()+
  geom_text_repel(data = subset(final_tumor, Adjusted.p.value < 0.05), 
                  aes(label = Feature.Name))

Now, I want to pull out a certain gene, Casp14, from the list and box it on the plot. How do I do that?

ggplot of rep_final

$\endgroup$

1 Answer 1

4
$\begingroup$

As you did for labeling genes with an adjusted p value below 0.05, you can subset your dataset for keeping only rows corresponding to "Casp14":

library(ggplot2)
library(ggrepel)
ggplot(final_tumor, aes(x = Log2.fold.change,y = -log10(Adjusted.p.value), label = Feature.Name))+ 
  geom_point()+
  geom_text_repel(data = subset(final_tumor, Adjusted.p.value < 0.05), 
                  aes(label = Feature.Name))+
  geom_text_repel(data = subset(final_tumor, Feature.Name == "Casp14"), 
                  aes(label = Feature.Name), color = "red")

With this code, you should see now the labeling of the gene of interest (Casp14) in red on your volcano plot.

$\endgroup$
11
  • $\begingroup$ How about for Enhanced volcano? I have this code EnhancedVolcano(final_tumor, lab = as.character(final_tumor$FeatureName), x = 'Log2.fold.change', y = 'Adjusted.p.value', xlim = c(-8,8), title = 'Tumor', pCutoff = 10e-5, FCcutoff = 1.5, pointSize = 3.0, labSize = 3.0) $\endgroup$
    – mmpp
    Jan 25, 2020 at 22:08
  • $\begingroup$ ggplot2 is taking forever to generate. $\endgroup$
    – mmpp
    Jan 25, 2020 at 23:24
  • $\begingroup$ How long is your dataset ? Maybe it is not relevant to plot all genes. Maybe, you can plot a representative part of your dataset (e.g. 2000 randomly selected genes). Regarding EnhancedVolcano, I do not have experience with it. Sorry. $\endgroup$
    – dc37
    Jan 26, 2020 at 2:52
  • $\begingroup$ How do I go about just plotting a representation of my dataset? $\endgroup$
    – mmpp
    Jan 26, 2020 at 3:07
  • $\begingroup$ you can use sample function to select random rows of your dataframe: rep_final = final_tumor[sample(1:nrow(final_tumor), size = 1000), ] $\endgroup$
    – dc37
    Jan 26, 2020 at 3:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.