# Plotting an average curve (loop) in R

I have data from a vertical jump testing session done with athletes. I am creating force-displacement loops - force is plotted on the y-axis, and the body centre of mass displacement is plotted on the x-axis.

The resulting curve which looks like a loop (read in the clockwise direction), begins with the athletes body weight (system force). Force then decreases as they descend and the downward displacement increases. This is followed by the ascent phase where the athlete's upward displacement increases until the point of toe off with a steadily decreasing force until the point of toe-off where the force is now zero. The athlete would then displace upwards into the air.

I would like to plot the mean force displacement curve for each athlete obtained from a series of jumps. I would also like to plot a 95% confidence band around the mean curve. The data is sampled at 1500 Hz and naturally, each jump has variability so the vectors for each of the jumps are not the same lengths.

I have tried using various summary and smoothing functions in ggplots but as the curve or 'loop' differs so much from linear and/or polynomial models, I have not figured out a method to make this work. I have also tried to find functions in other packages that address this type of problem but have had no luck.

I am hoping someone might have some ideas on how to determine a mean curve for this type of data using R (it's essentially a very awkwardly drawn circle). I know it is possible to do this in Matlab but I would prefer to find an R-Based solution. This has also become somewhat of a personal challenge of sorts.

I have provided a sample representation of what the data frame looks like below. Obviously the data frame below is drastically smaller than the actual data frames but nevertheless it gives a good representation to work with in order to develop a workable solution.

Thanks in advance for any thoughts or creative solutions!

Athlete Jump.Number      Displacement      Force
1        1                 0              800
1        1              -16.6667          400
1        1              -33.3334           50
1        1              -50.0001          400
1        1              -66.6668          800
1        1              -83.3335         1000
1        1              -100.000         1600
1        1                   -50         1400
1        1                    62            0
1        2                     0          802
1        2                -18.75          479
1        2                 -37.5           49
1        2                -56.25          514
1        2                   -75          900
1        2                -93.75         1500
1        2                   -40         1200
1        2                    60            0
1        3                     0          806
1        3                -13.64          379
1        3                -27.28           46
1        3                -40.92          367
1        3                -54.56          700
1        3                 -68.2         1167
1        3                -81.84         1400
1        3                -95.48         1700
1        3                  -100         2000
1        3                   -40         1567
1        3                    59            0
2        1                     0          900
2        1              -16.6667          500
2        1              -33.3334           90
2        1              -50.0001          500
2        1              -66.6668          900
2        1              -83.3335         1100
2        1              -100.000         1700
2        1                   -50         1500
2        1                    62            0
2        2                     0          902
2        2                -18.75          579
2        2                 -37.5          139
2        2                -56.25          514
2        2                   -75         1000
2        2                -93.75         1600
2        2                   -40         1300
2        2                    60            0
2        3                     0          906
2        3                -13.64          479
2        3                -27.28          116
2        3                -40.92          467
2        3                -54.56          800
2        3                 -68.2         1267
2        3                -81.84         1500
2        3                -95.48         1800
2        3                  -100         2100
2        3                   -40         1667
2        3                    59            0