Getting rid of tail end of data in R

Viewed 48

I have a data frame like this:

 head(fq)
    x  freq
1 150 12994
2 151   832
3 152   879
4 153   680
5 154   837
6 155   971

I plotted this with ggplot2: main img

And the zoomed in version is this. Now I want to calculate the point from where I should get rid of noisy tail end of the data: zoomed image

I tried to fit a curve with ggplot smooth as well.

     g<-ggplot(data = data.frame(fq), aes(x = x, y = freq))+
  geom_line()+labs(title = paste0("Peaks size distribution"),x = "counts", y = "frequency")+theme_bw()+
  scale_x_continuous(limits = c(0,2000),breaks = seq(0,2000,200))+
  scale_y_continuous(limits = c(0, 1000),breaks = seq(0,1000,100))+
  geom_smooth(aes(outfit=gfit<<-..y..),se = FALSE, method = "gam", formula = y ~ s(log(x)))

But After this I am not sure how to calculate the point where the slope significantly changes, so that I can cut from there, eye balling say around 400 in my added example graph. Do I need to calculate an inflection point, change point or just slopes?

I am also not sure if I might be stuck at around first peak in the beginning by calculating any of the above. Any suggestions will be very helpful!

0 Answers
Related