I have a set of x point pairs for drawing segments along the x axis to create a custom reading map in R:

Half of the task of constructing these segments solves its y positions, so that no two segments that overlap are at the same y level. For each segment, I iterate over the y levels from the first position until I get to a position that does not yet contain a segment that will overlap the current one. Then I record the end position of the current segment and move on to the next.
The actual code is a function as follows:
# Dummy data
My actual dataset is very large and contains regions that can contain up to 600,000 readings, as far as I can tell. The readings naturally add up to each other, so it is very easy to implement the worst-case scenario, where all readings overlap with each other. The time taken to create a large number of readings is unacceptable to me, so I'm looking for a way to make the process more efficient. Can I replace my loops with something faster? Is there an algorithm that can read readings faster? I really can't think of a better way to do this at the moment.
Thanks for your help.
source share