library(tidyverse)
library(patchwork)
library(ggalt)
library(ggbeeswarm)
library(gglogspline) # git.rud.is/hrbrmstr/gglogspline

# some IRL sample data from our (Rapid7) measurements of the uptime of
# Exim mail servers using hping3
if (!file.exists("~/Data/ld-exim-sample.txt.gz")) {
  download.file(
    url = "https://rud.is/dl/ld-exim-sample.txt.gz", 
    destfile = "~/Data/ld-exim-sample.txt.gz"
  )
}

con <- gzfile("~/Data/ld-exim-sample.txt.gz")

tibble(
  val = scan(con)
) -> xdf
## Read 20000 items

close(con)

summary(xdf$val)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1.00    9.02   20.94   21.71   32.91   59.29

(ggplot(xdf, aes(val)) + geom_histogram(bins = 100) + labs(title = "hist")) +
  (ggplot(xdf, aes(val)) + geom_density() + labs(title = "dens"))


(ggplot(xdf, aes(val)) + geom_histogram(bins = 100) + labs(title = "hist")) +
  (ggplot(xdf, aes(val)) + stat_logspline() + labs(title = "logspline"))


(ggplot(xdf, aes(val)) + geom_bkde(bandwidth = 0.5) + labs(title = "bkde")) +
  (ggplot(xdf, aes(val)) + stat_logspline() + labs(title = "logspline"))

IycgLS0tCiMnIHRpdGxlOiAie2dnbG9nc3BsaW5lfSBFeGFtcGxlIgojJyBhdXRob3I6ICJAaHJicm1zdHIiCiMnIGRhdGU6ICIyMDE5LTA2LTE4IgojJyBvdXRwdXQ6CiMnICAgaHRtbF9kb2N1bWVudDoKIycgICAgIGtlZXBfbWQ6IHRydWUKIycgICAgIHRoZW1lOiBzaW1wbGV4CiMnICAgICBoaWdobGlnaHQ6IG1vbm9jaHJvbWUKIycgICAgIGNvZGVfZG93bmxvYWQ6IHRydWUKIycgLS0tCiMrIGluaXQsIGluY2x1ZGU9RkFMU0UKa25pdHI6Om9wdHNfY2h1bmskc2V0KG1lc3NhZ2UgPSBGQUxTRSwgd2FybmluZyA9IEZBTFNFLCBkZXY9InBuZyIsIGNvbGxhcHNlPVRSVUUsCiAgICAgICAgICAgICAgICAgICAgICB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