ggrepel: Repelling text in only one direction, and returning values of repelled text
<p>I have a dataset, where each data point has an x-value that is constrained (represents an actual instance of a quantitative variable), y-value that is arbitrary (exists simply to provide a dimension to spread out text), and a label. My datasets can be very large, and there is often text overlap, even when I try to spread the data across the y-axis as much as possible.</p>

<p>Hence, I am trying to use the new ggrepel. However, I am trying to keep the text labels constrained at their x-value position, while only allowing them to repel from each other in the y-direction.</p>

<p>As an example, the below code produces an plot for 32 data points, where the x-values show the number of cylinders in a car, and the y-values are determined randomly (have no meaning but to provide a second dimension for text plotting purposes). Without using ggrepel, there is significant overlap in the text:</p>

<pre><code>library(ggrepel)
library(ggplot2)
set.seed(1)
data = data.frame(x=runif(100, 1, 10),y=runif(100, 1, 10),label=paste0("label",seq(1:100)))
origPlot &lt;- ggplot(data) +
  geom_point(aes(x, y), color = 'red') +
  geom_text(aes(x, y, label = label)) +
  theme_classic(base_size = 16)
</code></pre>

<p><a href="https://i.stack.imgur.com/03ki4.png" rel="noreferrer"><img src="https://i.stack.imgur.com/03ki4.png" alt="Original plot"></a></p>

<p>I can remedy the text overlap using ggrepel, as shown below. However, this changes not only the y-values, but also the x-values. I am trying to avoid changing the x-values, as they represent an actual physical meaning (the number of cylinders):</p>

<pre><code>repelPlot &lt;- ggplot(data) +
  geom_point(aes(x, y), color = 'red') +
  geom_text_repel(aes(x, y, label = label)) +
  theme_classic(base_size = 16)
</code></pre>

<p><a href="https://i.stack.imgur.com/ESpkT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ESpkT.png" alt="enter image description here"></a></p>

<p>As a note, the reason I cannot allow the x-value of the text to change is because I am only plotting the text (not the points). Whereas, it seems that most examples in ggrepel keep the position of the points (so that their values remain true), and only repel the x and y values of the labels. Then, the points and connected to the labels with segments (you can see that in my second plot example).</p>

<p>I kept the points in the two examples above for demonstration purposes. However, I am only retaining the text (and hence will be removing the points and the segments), leaving me with something like this:</p>

<pre><code>repelPlot2 &lt;- ggplot(data) + geom_text_repel(aes(x, y, label = label), segment.size = 0) + theme_classic(base_size = 16)
</code></pre>

<p><a href="https://i.stack.imgur.com/QRJTt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/QRJTt.png" alt="enter image description here"></a></p>

<p>My question is two fold:</p>

<p>1) Is it possible for me to repel the text labels only in the y-direction?</p>

<p>2) Is it possible for me to obtain a structure containing the new (repelled) y-values of the text?</p>

<p>Thank you for any advice!</p>