title: How to avoid overlapping of text labels in ggrepel
body: <p>I tried every single thing in this tutorial: <a href="https://ggrepel.slowkow.com/articles/examples.html" rel="nofollow noreferrer">https://ggrepel.slowkow.com/articles/examples.html</a>
  but I wasn't successful repelling the text from each other and keep them aligned without overlapping,
  I want something like this:
  <a href="https://i.stack.imgur.com/zEJwt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zEJwt.png" alt="enter image description here" /></a></p>
  <p>But with my trials, I get something like this:</p>
  <p><a href="https://i.stack.imgur.com/UswTz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UswTz.png" alt="enter image description here" /></a></p>
  <p>My code:</p>
  <pre><code>library(ggplot2)
  library(ggrepel)
  library(dplyr)
  library(cowplot)
  
  #Data
  fig5cwithoutdesc &lt;- read.csv(url(&quot;https://raw.githubusercontent.com/learnseq/learning/main/fig5cwithoutdesc.txt&quot;),sep = '\t',header = TRUE)
  fig5cwithoutdesc$geneIDs &lt;- trimws(gsub('[[:punct:] ]+',' ',fig5cwithoutdesc$geneIDs))
  fig5cwithoutdesc$geneIDs.1 &lt;- trimws(gsub('[[:punct:] ]+',' ',fig5cwithoutdesc$geneIDs.1))
  fig5cwithoutdesc$geneIDs.2 &lt;- trimws(gsub('[[:punct:] ]+',' ',fig5cwithoutdesc$geneIDs.2))
  fig5cwithoutdesc$geneIDs.3 &lt;- trimws(gsub('[[:punct:] ]+',' ',fig5cwithoutdesc$geneIDs.3))
  fig5cwithoutdesc$geneIDs.4 &lt;- trimws(gsub('[[:punct:] ]+',' ',fig5cwithoutdesc$geneIDs.4))
  fig5cwithoutdesc$geneIDs.5 &lt;- trimws(gsub('[[:punct:] ]+',' ',fig5cwithoutdesc$geneIDs.5))
  
  idza &lt;- c(&quot;RPL31&quot;, &quot;HSPB1&quot;, &quot;MAFB&quot;, &quot;ALPL1&quot;, &quot;VGF&quot;,&quot;PCSK1N&quot;, &quot;BSG&quot;, &quot;CALY&quot;, &quot;B2M&quot;, &quot;SCG5&quot;, &quot;TM4SF4&quot;)
  idzb &lt;- c(&quot;MAFA&quot;, &quot;PDX1&quot;, &quot;INS&quot;, &quot;KCNQ2&quot;, &quot;OLFM2&quot;, &quot;C1QL1&quot;, &quot;PCSKI1N&quot;, &quot;SNHG7&quot;, &quot;SRP9&quot;, &quot;SET&quot;, &quot;CALM2&quot;, &quot;NDUFA1&quot;, &quot;B2M&quot;, &quot;PCP4&quot;, &quot;SCG3&quot;,&quot;PFKFB2&quot;)
  idzg &lt;- c(&quot;PPY&quot;, &quot;CLU&quot;, &quot;GIGYF1&quot;, &quot;PTP4A3&quot;, &quot;EIF5A&quot;, &quot;ALDOA&quot;, &quot;CFL1&quot;, &quot;NPDC1&quot;, &quot;CTSD&quot;, &quot;RPLP1&quot;, &quot;PCSK1N&quot;, &quot;DDX5&quot;, &quot;SCG5&quot;, &quot;CPG5&quot;, &quot;CPE&quot;, &quot;LOC643355&quot;)
  idzd &lt;- c(&quot;RBP4&quot;, &quot;SST&quot;, &quot;PDX1&quot;, &quot;C19orf66&quot;, &quot;CELF3&quot;, &quot;PCSK1N&quot;, &quot;TPGS1&quot;, &quot;PODXL2&quot;, &quot;CDK5R2&quot;, &quot;CALY&quot;, &quot;LOC728392&quot;, &quot;SET&quot;, &quot;SRP9&quot;, &quot;TSPYL1&quot;, &quot;TPD52&quot;, &quot;PCP4&quot;)
  idzacinar &lt;- c(&quot;SGK223&quot;, &quot;JUND&quot;, &quot;RPL7A&quot;, &quot;AP1S1&quot;, &quot;RBP4&quot;, &quot;ENPP2&quot;, &quot;ARF4&quot;, &quot;TM4SF4&quot;, &quot;ATP5O&quot;, &quot;PSMD10&quot;, &quot;DYNLL1&quot;)
  idzductal &lt;- c(&quot;YBX3&quot;, &quot;SERINC2&quot;, &quot;PRSS22&quot;, &quot;HLA-A&quot;, &quot;PPDPF&quot;, &quot;EEF2&quot;, &quot;SRP9&quot;, &quot;SKP1&quot;, &quot;B2M&quot;, &quot;SDCBP&quot;, &quot;CNN3&quot;)
  
  
  
  
  
      
      
      
  library(repr, warn.conflicts = FALSE)
  options(repr.plot.width=6, repr.plot.height=4)
  
  za &lt;- ggplot(fig5cwithoutdesc,
         aes(a_donor, a_cell, color=(geneIDs %in% idza)))+
    geom_point()+
    scale_color_manual(values = c('gray','royalblue1')) +
    geom_text_repel(data=subset(fig5cwithoutdesc,geneIDs %in% idza),
                    aes(x=a_donor, y=a_cell,label=geneIDs, force=10), 
                    color='black',
                    nudge_y = 0.01,
                    direction = &quot;x&quot;,
                    angle = 0,
                    hjust = 0,
                    vjust = 1,
                    segment.size = 0.5) +
    theme_bw()+
    theme(legend.position = 'none', panel.grid.major = element_blank(), panel.grid.minor = element_blank())
  
  zb &lt;- ggplot(fig5cwithoutdesc,
         aes(b_donor, b_cell, color=(geneIDs.1 %in% idzb)))+
    geom_point()+
    scale_color_manual(values = c('gray','orange')) +
    geom_text_repel(data=subset(fig5cwithoutdesc,geneIDs.1 %in% idzb),
                    aes(x=b_donor, y=b_cell,label=geneIDs.1, force=10), 
                    color='black',
                    nudge_y = 0.01,
                    direction = &quot;x&quot;,
                    angle = 0,
                    hjust = 1,
                    vjust = 1,
                    segment.size = 0.5) +
    theme_bw()+
    theme(legend.position = 'none', panel.grid.major = element_blank(), panel.grid.minor = element_blank())
  
  
  zg &lt;- ggplot(fig5cwithoutdesc,
         aes(g_donor, g_cell, color=(geneIDs.2 %in% idzg)))+
    geom_point()+
    scale_color_manual(values = c('gray','brown2')) +
    geom_text_repel(data=subset(fig5cwithoutdesc,geneIDs.2 %in% idzg),
                    aes(x=g_donor, y=g_cell,label=geneIDs.2, force=10), 
                    color='black',
                    nudge_y = 0.01,
                    direction = &quot;x&quot;,
                    angle = 0,
                    hjust = 1,
                    vjust = 1,
                    segment.size = 0.5) +
    theme_bw()+
    theme(legend.position = 'none', panel.grid.major = element_blank(), panel.grid.minor = element_blank())
  
  
  zd &lt;- ggplot(fig5cwithoutdesc,
         aes(d_donor, d_cell, color=(geneIDs.3 %in% idzd)))+
    geom_point()+
    scale_color_manual(values = c('gray','cyan')) +
    geom_text_repel(data=subset(fig5cwithoutdesc,geneIDs.3 %in% idzd),
                    aes(x=d_donor, 
                        y=d_cell,
                        label=geneIDs.3, 
                        force=10), 
                    color='black',
                    segment.size  = 0.2,
                    segment.color = &quot;grey50&quot;, 
                    direction     = &quot;y&quot;, 
                    hjust         = 1) +
    theme_bw()+
    theme(legend.position = 'none', panel.grid.major = element_blank(), panel.grid.minor = element_blank())
  
  
  zacinar &lt;- ggplot(fig5cwithoutdesc,
         aes(acinar_donor, acinar_cell, color=(geneIDs.4 %in% idzacinar)))+
    geom_point()+
    scale_color_manual(values = c('gray','purple')) +
    geom_text_repel(data=subset(fig5cwithoutdesc,geneIDs.4 %in% idzacinar),
                    aes(x=acinar_donor, y=acinar_cell,label=geneIDs.4, force=10), 
                    color='black',
                    nudge_y = 0.01,
                    direction = &quot;x&quot;,
                    angle = 0,
                    hjust = 1,
                    vjust = 1,
                    segment.size = 0.5) +
    theme_bw()+
    theme(legend.position = 'none', panel.grid.major = element_blank(), panel.grid.minor = element_blank())
  
  
  zductal &lt;- ggplot(fig5cwithoutdesc,
         aes(ductal_donor, ductal_cell, color=(geneIDs.5 %in% idzductal)))+
    geom_point()+
    scale_color_manual(values = c('gray','blue1')) +
    geom_text_repel(data=subset(fig5cwithoutdesc,geneIDs.5 %in% idzductal),
                    aes(x=ductal_donor, y=ductal_cell,label=geneIDs.5, force=10), 
                    color='black',
                    nudge_y = 0.01,
                    direction = &quot;x&quot;,
                    angle = 0,
                    hjust = 1,
                    vjust = 1,
                    segment.size = 0.5) +
    theme_bw()+
    theme(legend.position = 'none', panel.grid.major = element_blank(), panel.grid.minor = element_blank())
  
  
  library(repr, warn.conflicts = FALSE)
  options(repr.plot.width=17, repr.plot.height=10)
  
  plot_grid(za, zb, zg, zd, zacinar, zductal, nrow=2, labels= &quot;AUTO&quot;)
  
  
  </code></pre>
  <p>How to achieve the same thing in the first image?</p>