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:
to this:
• 1,082 views
•
link
2 answers
The easiest will be to exchange the geom_line() layer for a geom_smooth().
• 0 views
•
link
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:
- https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.rolling.html
- https://www.geeksforgeeks.org/how-to-calculate-moving-average-in-a-pandas-dataframe/
- https://stackoverflow.com/questions/14313510/how-to-calculate-rolling-moving-average-using-python-numpy-scipy
- https://www.delftstack.com/howto/python/moving-average-python/
• 0 views
•
link
Log in to answer this question.
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.