This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Make a line chart flatter

I used R package "ggplot2" to draw a line chart. Now i want to make it flatter. Is there any data processing or graphical processing that can do this? Like this: enter image description here

to this: enter image description here

r plot

Check out geom_smooth(), using something like a Loess regression fit or a GAM. Essentially, it will come down to smoothing out these outliers to get a nicer "flat" line.

2 answers

The easiest will be to exchange the geom_line() layer for a geom_smooth().

This is a simple sliding window averaging.

https://en.wikipedia.org/wiki/Moving_average

Ideally the window size should be an odd number, and larger windows will cause more smoothing of the plot. I would imagine that 11-21 range would work for your plot.

There are existing solutions to calculate the new values:

Log in to answer this question.