Make a line chart flatter
2
0
Entering edit mode
23 months ago
3095916029 • 0

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 • 643 views
ADD COMMENT
1
Entering edit mode

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.

ADD REPLY
1
Entering edit mode
23 months ago

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

ADD COMMENT
0
Entering edit mode
23 months ago
Mensur Dlakic ★ 27k

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:

ADD COMMENT

Login before adding your answer.

Traffic: 1987 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6