Deriving Quantiles or Percentiles in R

Percentiles can be calculated in R using the quantile function. The function has the argument type which allows for nine different percentile definitions to be used. The default is type = 7, which uses a piecewise-linear estimate of the cumulative distribution function to find percentiles.

This is how the 25th and 40th percentiles of aval could be calculated using the default type.

quantile(aval, probs = c(0.25, 0.4))
─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.3 (2026-03-11)
 os       Ubuntu 24.04.4 LTS
 system   x86_64, linux-gnu
 ui       X11
 language (EN)
 collate  C.UTF-8
 ctype    C.UTF-8
 tz       UTC
 date     2026-08-25
 pandoc   3.10 @ /opt/quarto/bin/tools/ (via rmarkdown)
 quarto   1.10.18 @ /usr/local/bin/quarto

─ Packages ───────────────────────────────────────────────────────────────────
 ! package     * version date (UTC) lib source
 P cli           3.6.6   2026-04-09 [?] RSPM (R 4.5.0)
 P digest        0.6.39  2025-11-19 [?] RSPM (R 4.5.0)
 P evaluate      1.0.5   2025-08-27 [?] RSPM (R 4.5.0)
 P fastmap       1.2.0   2024-05-15 [?] RSPM (R 4.5.0)
 P htmltools     0.5.9   2025-12-04 [?] RSPM (R 4.5.0)
 P htmlwidgets   1.6.4   2023-12-06 [?] RSPM (R 4.5.0)
 P jsonlite      2.0.0   2025-03-27 [?] RSPM (R 4.5.0)
 P knitr         1.51    2025-12-20 [?] RSPM (R 4.5.0)
 P otel          0.2.0   2025-08-29 [?] RSPM (R 4.5.0)
   renv          1.0.10  2024-10-05 [1] RSPM (R 4.5.3)
 P rlang         1.3.0   2026-07-05 [?] RSPM (R 4.5.0)
 P rmarkdown     2.31    2026-03-26 [?] RSPM (R 4.5.0)
 P sessioninfo   1.2.4   2026-06-04 [?] RSPM (R 4.5.0)
 P xfun          0.60    2026-07-09 [?] RSPM (R 4.5.0)
 P yaml          2.3.12  2025-12-10 [?] RSPM (R 4.5.0)

 [1] /home/runner/work/CAMIS/CAMIS/renv/library/linux-ubuntu-noble/R-4.5/x86_64-pc-linux-gnu
 [2] /opt/R/4.5.3/lib/R/library

 P ── Loaded and on-disk path mismatch.

──────────────────────────────────────────────────────────────────────────────

Note: geom_boxplot and stats_boxplot in ggplot2 uses the default of type = 7. It is not possible to switch the type of algorithm used to compute the quantiles in these functions for ggplot2.