lib(ggplot) DT.scores_all.counts <- DT.scores_all[, .N, keyby=list(accel_score_scaled=round(accel_score_scaled, 4))] DT.scores_all <- sfQry("SELECT round(accel_score_scaled, 4) AS accel_score_scaled, count(*) as counts FROM spotify.weekly_counts_by_track_and_source WHERE accel_score_scaled IS NOT NULL GROUP BY 1 ORDER BY 1") jesusForData(DT.scores_all) digits <- 2 DT.scores_all.counts <- DT.scores_all[, list(counts=sumn(counts)), keyby=list(accel_score_scaled=round(accel_score_scaled, digits=digits))][, csum := cumsum(counts)][, cperc := cumsum(counts) / sumn(counts)] ggplot(data=DT.scores_all.counts, aes(x=accel_score_scaled, y=counts)) + geom_line(se=FALSE) ggplot(data=DT.scores_all.counts, aes(x=accel_score_scaled, y=cperc)) + geom_line(se=FALSE) DT.scores_all.counts[, cperc.fmt := fwp(cperc, dec=4)] DT.scores_all.counts[cperc > .9] DT.scores_all[order(accel_score_scaled), csum := cumsum(counts)] quantiles()