<p>Based on your comments, you wish to obtain a semi-colon separated list of unique values in the gene column. You can create a new column containing these using:</p>
<pre class="lang-r prettyprint-override"><code>xyz &lt;- data.frame(chr=&quot;chr1&quot;, gene = c(&quot;RUNX3;RUNX3&quot;, &quot;RUNX3;RUNX3&quot;, &quot;SFN&quot;, &quot;NR0B2&quot;, &quot;NR0B2&quot;, &quot;TFAP2E&quot;, &quot;A;B;A&quot;))

xyz
   chr        gene
1 chr1 RUNX3;RUNX3
2 chr1 RUNX3;RUNX3
3 chr1         SFN
4 chr1       NR0B2
5 chr1       NR0B2
6 chr1      TFAP2E
7 chr1       A;B;A

xyz<span class="math-container">$gene_uniq &lt;- sapply(xyz$</span>gene, function(x) paste(unique(unlist(strsplit(x, &quot;;&quot;))), collapse=&quot;;&quot;))

xyz
   chr        gene gene_uniq
1 chr1 RUNX3;RUNX3     RUNX3
2 chr1 RUNX3;RUNX3     RUNX3
3 chr1         SFN       SFN
4 chr1       NR0B2     NR0B2
5 chr1       NR0B2     NR0B2
6 chr1      TFAP2E    TFAP2E
7 chr1       A;B;A       A;B
</code></pre>
<p>Or you can use dplyr. I'm adding a column called <code>entry_num</code> below since my example has non-unique combinations of chr and gene that we need to retain.</p>
<pre class="lang-r prettyprint-override"><code>library(dplyr)
library(tidyr)

xyz &lt;- data.frame(chr=&quot;chr1&quot;, gene = c(&quot;RUNX3;RUNX3&quot;, &quot;RUNX3;RUNX3&quot;, &quot;SFN&quot;, &quot;NR0B2&quot;, &quot;NR0B2&quot;, &quot;TFAP2E&quot;, &quot;A;B;A&quot;))
xyz %&gt;% mutate(entry_num = 1:nrow(xyz)) %&gt;% separate_rows(gene, sep = &quot;;&quot;) %&gt;% unique() %&gt;% group_by(chr, entry_num) %&gt;% summarize(gene = paste(gene, collapse=&quot;;&quot;)) %&gt;% select(-entry_num) %&gt;% as.data.frame()

   chr   gene
1 chr1  RUNX3
2 chr1  RUNX3
3 chr1    SFN
4 chr1  NR0B2
5 chr1  NR0B2
6 chr1 TFAP2E
7 chr1    A;B
</code></pre>

CC BY-SA 4.0
2023-12-21T16:41:37.647Z
2023-12-21T16:46:40.133Z
2023-12-21T16:46:40.133Z
Ram RS
<p>I'm wondering how can I show unique gene names in the volcano plot.</p>
<p>My data looks like,</p>
<pre class="lang-r prettyprint-override"><code>head(DMCf1_huMetGNc)
     chr    start    end.x       pvalue       qvalue meth.diff        gene
152 chr1 24909805 24909805 1.915400e-03 0.0168087962 -52.00000 RUNX3;RUNX3
168 chr1 24931440 24931440 8.645625e-03 0.0489503201  28.98551 RUNX3;RUNX3
179 chr1 26862096 26862096 1.308307e-04 0.0023224596 -42.48366         SFN
187 chr1 26914178 26914178 4.508416e-06 0.0001786963 -57.97872       NR0B2
188 chr1 26914203 26914203 5.337425e-05 0.0011910452 -47.30424       NR0B2
194 chr1 35573100 35573100 1.433689e-03 0.0135780139 -42.04545      TFAP2E
</code></pre>
<p>The original data file is quite large, here under the <code>gene</code> column some of the rows have multiple same gene names separated by <code>;</code>. How can I show only unique gene names.</p>
<p>No pattern of gene names exists when multiple names are present. In certain cases, the same gene is repeated, while in other cases, distinct genes are present in the same cell. The majority of the time, a single gene exists in a cell.</p>
<pre class="lang-r prettyprint-override"><code>library(ggplot2)
library(ggrepel)
    v1&lt;-ggplot(data=DMCf1_huMetGNc, aes(x=meth.diff, y=-log10(pvalue) )) + geom_point()
    v1+geom_text_repel(aes(label= gene))
</code></pre>
<p><a href="https://i.sstatic.net/KuoIc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/KuoIc.png" alt="enter image description here" /></a></p>
<p>Here, you may see how the FGFR2 gene is repetitive in the plot that I want to remove and the same name from a single row should appear only once in the plot.</p>

CC BY-SA 4.0
2023-12-19T20:46:57.357Z
What do you want done with lines that include multiple gene names?
gringer
CC BY-SA 4.0
2023-12-20T15:04:27.760Z
I want to show the unique names only, not the same repetitive  names.
Deb
CC BY-SA 4.0
2023-12-20T18:12:35.460Z
So if there's `A;B;A`, you wish to show `A;B` and if there's `A;A`, you want just `A`?
Ram RS
CC BY-SA 4.0
2023-12-20T19:14:37.780Z
This explanation is not descriptive enough. Do you want lines to be duplicated, one for each gene? Do you want to exclude lines with multiple genes? Or something else?
gringer
CC BY-SA 4.0
2023-12-21T15:19:05.020Z
Yes,  RamRS is true. I want to show the names as @RamRS is suggested.
Deb
<r><genomics><ggplot2><methylation>
Volcano Plot: How to show unique gene names in the plot?
# Volcano Plot: How to show unique gene names in the plot?

(Asked by: username_0 on 2023-12-18)

I'm wondering how can I show unique gene names in the volcano plot.
My data looks like,
head(DMCf1_huMetGNc)
     chr    start    end.x       pvalue       qvalue meth.diff        gene
152 chr1 24909805 24909805 1.915400e-03 0.0168087962 -52.00000 RUNX3;RUNX3
168 chr1 24931440 24931440 8.645625e-03 0.0489503201  28.98551 RUNX3;RUNX3
179 chr1 26862096 26862096 1.308307e-04 0.0023224596 -42.48366         SFN
187 chr1 26914178 26914178 4.508416e-06 0.0001786963 -57.97872       NR0B2
188 chr1 26914203 26914203 5.337425e-05 0.0011910452 -47.30424       NR0B2
194 chr1 35573100 35573100 1.433689e-03 0.0135780139 -42.04545      TFAP2E

The original data file is quite large, here under the gene column some of the rows have multiple same gene names separated by ;. How can I show only unique gene names.
No pattern of gene names exists when multiple names are present. In certain cases, the same gene is repeated, while in other cases, distinct genes are present in the same cell. The majority of the time, a single gene exists in a cell.
library(ggplot2)
library(ggrepel)
    v1<-ggplot(data=DMCf1_huMetGNc, aes(x=meth.diff, y=-log10(pvalue) )) + geom_point()
    v1+geom_text_repel(aes(label= gene))


Here, you may see how the FGFR2 gene is repetitive in the plot that I want to remove and the same name from a single row should appear only once in the plot.

**Tags:** r, genomics, ggplot2, methylation
> **Comments:**
> **username_1**: What do you want done with lines that include multiple gene names?  
> **username_0**: I want to show the unique names only, not the same repetitive  names.  
> **username_2**: So if there's `A;B;A`, you wish to show `A;B` and if there's `A;A`, you want just `A`?  
> **username_1**: This explanation is not descriptive enough. Do you want lines to be duplicated, one for each gene? Do you want to exclude lines with multiple genes? Or something else?  
> **username_0**: Yes,  RamRS is true. I want to show the names as @RamRS is suggested.  

---

## 1 answers

### Answer by username_2 on 2023-12-21. Score: 1

Based on your comments, you wish to obtain a semi-colon separated list of unique values in the gene column. You can create a new column containing these using:
xyz <- data.frame(chr="chr1", gene = c("RUNX3;RUNX3", "RUNX3;RUNX3", "SFN", "NR0B2", "NR0B2", "TFAP2E", "A;B;A"))

xyz
   chr        gene
1 chr1 RUNX3;RUNX3
2 chr1 RUNX3;RUNX3
3 chr1         SFN
4 chr1       NR0B2
5 chr1       NR0B2
6 chr1      TFAP2E
7 chr1       A;B;A

xyz$gene_uniq <- sapply(xyz$gene, function(x) paste(unique(unlist(strsplit(x, ";"))), collapse=";"))

xyz
   chr        gene gene_uniq
1 chr1 RUNX3;RUNX3     RUNX3
2 chr1 RUNX3;RUNX3     RUNX3
3 chr1         SFN       SFN
4 chr1       NR0B2     NR0B2
5 chr1       NR0B2     NR0B2
6 chr1      TFAP2E    TFAP2E
7 chr1       A;B;A       A;B

Or you can use dplyr. I'm adding a column called entry_num below since my example has non-unique combinations of chr and gene that we need to retain.
library(dplyr)
library(tidyr)

xyz <- data.frame(chr="chr1", gene = c("RUNX3;RUNX3", "RUNX3;RUNX3", "SFN", "NR0B2", "NR0B2", "TFAP2E", "A;B;A"))
xyz %>% mutate(entry_num = 1:nrow(xyz)) %>% separate_rows(gene, sep = ";") %>% unique() %>% group_by(chr, entry_num) %>% summarize(gene = paste(gene, collapse=";")) %>% select(-entry_num) %>% as.data.frame()

   chr   gene
1 chr1  RUNX3
2 chr1  RUNX3
3 chr1    SFN
4 chr1  NR0B2
5 chr1  NR0B2
6 chr1 TFAP2E
7 chr1    A;B


---

