Answers.Body: <p>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":</p>
  
  <pre class="lang-r prettyprint-override"><code>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 &lt; 0.05), 
                    aes(label = Feature.Name))+
    geom_text_repel(data = subset(final_tumor, Feature.Name == "Casp14"), 
                    aes(label = Feature.Name), color = "red")
  </code></pre>
  
  <p>With this code, you should see now the labeling of the gene of interest (Casp14) in red on your volcano plot. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-25T22:08:40.683Z
Answers.Text: 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)`
Answers.UserDisplayName: mmpp
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-25T23:24:34.703Z
Answers.Text: ggplot2 is taking forever to generate.
Answers.UserDisplayName: mmpp
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-26T02:52:02.087Z
Answers.Text: 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.
Answers.UserDisplayName: dc37
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-26T03:07:46.603Z
Answers.Text: How do I go about just plotting a representation of my dataset?
Answers.UserDisplayName: mmpp
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-26T03:11:22.843Z
Answers.Text: you can use `sample` function to select random rows of your dataframe: `rep_final = final_tumor[sample(1:nrow(final_tumor), size = 1000), ]`
Answers.UserDisplayName: dc37
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-26T03:13:41.700Z
Answers.Text: Where in `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")` do I add it?
Answers.UserDisplayName: mmpp
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-26T03:15:02.473Z
Answers.Text: Do it before ggplot to create a subset of your dataframe `final_tumor` and then replace `final_tumor` by `rep_final` in the ggplot command
Answers.UserDisplayName: dc37
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-26T15:04:42.627Z
Answers.Text: Is there a way to make it look nicer? I uploaded the image to the question.
Answers.UserDisplayName: mmpp
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-26T15:26:05.950Z
Answers.Text: To reduce the number of labeled genes on your graph, you could choose a more stringent cutoff for the labeling. For example, instead of labeling genes with p values below 0.05, you can plot those that have an absolute logFC higher than 1 or 2 or 3 ... whatever. At the end, it's up to you. You have to think what is important to show with this graph and what should be the message that you sent with this graph. BTW, your question in comments is beyond the question of this post ;)
Answers.UserDisplayName: dc37
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-26T17:43:31.300Z
Answers.Text: Okay, I will create a new question.
Answers.UserDisplayName: mmpp
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-27T04:35:09.367Z
Answers.Text: Sure. As you wish. By the way, as you are a new contributor, you should take a second to read this: https://bioinformatics.stackexchange.com/help/someone-answers
Answers.UserDisplayName: dc37
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-25T20:12:20.550Z
Answers.LastActivityDate: 2020-01-25T20:12:20.550Z
Answers.UserDisplayName: dc37
Body: <p>I have generated a volcano plot with a differential expression file.</p>
  
  <p>Code for inputing file:</p>
  
  <p><code>macrophage_list &lt;- read.table("differential_expression_macrophage.csv", header = T, sep = ",")</code></p>
  
  <pre><code>library(tidyr)
  final_df &lt;- df %&gt;% 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
     &lt;fct&gt;      &lt;fct&gt;        &lt;chr&gt;           &lt;dbl&gt;            &lt;dbl&gt;            &lt;dbl&gt;
   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
  </code></pre>
  
  <p>output of head(final_tumor)</p>
  
  <pre><code># A tibble: 6 x 6
    Feature.ID        Feature.Name set       Mean.Counts Log2.fold.change Adjusted.p.value
    &lt;fct&gt;             &lt;fct&gt;        &lt;chr&gt;           &lt;dbl&gt;            &lt;dbl&gt;            &lt;dbl&gt;
  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 
  </code></pre>
  
  <p>output of tail(final_tumor)</p>
  
  <pre><code># A tibble: 6 x 6
    Feature.ID        Feature.Name set        Mean.Counts Log2.fold.change Adjusted.p.value
    &lt;fct&gt;             &lt;fct&gt;        &lt;chr&gt;            &lt;dbl&gt;            &lt;dbl&gt;            &lt;dbl&gt;
  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></pre>
  
  <p>Code for generating volcano plot:</p>
  
  <pre><code>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 &lt; 0.05), 
                    aes(label = Feature.Name))
  </code></pre>
  
  <p>Now, I want to pull out a certain gene, Casp14, from the list and box it on the plot. How do I do that?</p>
  
  <p><a href="https://i.sstatic.net/PCi7U.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PCi7U.png" alt="ggplot of rep_final"></a></p>
  
Tags: <r><ggplot2>
Title: Pulling out a certain gene in a volcano plot
ThreadText: # Pulling out a certain gene in a volcano plot
  
  (Asked by: username_0 on 2020-01-25)
  
  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](https://i.sstatic.net/PCi7U.png)](https://i.sstatic.net/PCi7U.png)
  
  **Tags:** r, ggplot2
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-01-25. Score: 4 | Accepted answer
  
  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":
  
  ```r
  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.
  
  > **Comments:**
  > **username_0**: 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)`  
  > **username_0**: ggplot2 is taking forever to generate.  
  > **username_1**: 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.  
  > **username_0**: How do I go about just plotting a representation of my dataset?  
  > **username_1**: you can use `sample` function to select random rows of your dataframe: `rep_final = final_tumor[sample(1:nrow(final_tumor), size = 1000), ]`  
  > **username_0**: Where in `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")` do I add it?  
  > **username_1**: Do it before ggplot to create a subset of your dataframe `final_tumor` and then replace `final_tumor` by `rep_final` in the ggplot command  
  > **username_0**: Is there a way to make it look nicer? I uploaded the image to the question.  
  > **username_1**: To reduce the number of labeled genes on your graph, you could choose a more stringent cutoff for the labeling. For example, instead of labeling genes with p values below 0.05, you can plot those that have an absolute logFC higher than 1 or 2 or 3 ... whatever. At the end, it's up to you. You have to think what is important to show with this graph and what should be the message that you sent with this graph. BTW, your question in comments is beyond the question of this post ;)  
  > **username_0**: Okay, I will create a new question.  
  > **username_1**: Sure. As you wish. By the way, as you are a new contributor, you should take a second to read this: https://bioinformatics.stackexchange.com/help/someone-answers  
  
  ---
  
  