Algorithm that shifts points in the x-y plane to maximize distance but keep one axis constant

Suppose I am running an experiment with some subjects, and I obtain some numerical data from them. The subjects are divided into 2 experimental groups. Rather than display the means of each group in a bar graph, I would like to show their individual data. So I plot the data like so:

This is all fine and good, but let's say some individuals within a group have the same data. In this case, you would not be able to see each individual's data in a plot like this because their datapoints would completely overlap. Even individuals with data that was almost-the-same-but-not-quite would have some overlap, and it could be confusing to someone looking at the graph because they wouldn't see all the data.

In such a scenario, it would be useful to plot the data with individuals that have the same data just slightly offset from each other on the X-axis, like so:

This makes it so each datapoint is clear and visible for the reader.

Now comes the question: if I have a dataset that looks similar to the figure above, and I want to choose "x axis values" for each point to properly plot my data so that each datapoint is visible to the user, is there an algorithm that will essentially maximize distance of points from each other on the x-axis (within some pre-defined bounds, of course) while keeping their y-axis values constant?

• So if you sort data by y value, mark (assign range, "cluster") for those at distance r, calculate the max clustered points to give centering and then shift points accordingly, would it work? – Evil Jul 14 '17 at 0:14
• The simplest approach is to add some noise to all points. This would separate identical points. If you don't like the idea of noise, you can make it deterministic noise that depends only on the point number (i.e., add deterministic noise $n_i$ depending on $i$ to point $p_i$). – Yuval Filmus Jul 14 '17 at 7:07
• Is this a data visualization problem? If so, why don't you plot Figure 1, but color each point according to the number of individuals at the same point? – Koo Zhengqun Jul 19 '17 at 1:48