{"id":13711235,"url":"https://mjskay.github.io/ggdist/","last_synced_at":"2025-05-06T20:32:35.534Z","repository":{"id":37288998,"uuid":"269511995","full_name":"mjskay/ggdist","owner":"mjskay","description":"Visualizations of distributions and uncertainty","archived":false,"fork":false,"pushed_at":"2024-07-27T03:31:48.000Z","size":256432,"stargazers_count":850,"open_issues_count":56,"forks_count":26,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-11T10:53:05.714Z","etag":null,"topics":["ggplot2","r","r-package","uncertainty","uncertainty-visualization","visualization"],"latest_commit_sha":null,"homepage":"https://mjskay.github.io/ggdist/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mjskay.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-05T02:26:40.000Z","updated_at":"2024-11-08T08:31:57.000Z","dependencies_parsed_at":"2023-10-05T01:38:35.872Z","dependency_job_id":"8e8c19e9-b80e-4ca3-bd34-160ced1b33fa","html_url":"https://github.com/mjskay/ggdist","commit_stats":{"total_commits":1622,"total_committers":7,"mean_commits":"231.71428571428572","dds":0.03390875462392107,"last_synced_commit":"076e04ea7c2929051225d6053d69d9e58072301a"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjskay%2Fggdist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjskay%2Fggdist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjskay%2Fggdist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjskay%2Fggdist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mjskay","download_url":"https://codeload.github.com/mjskay/ggdist/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224219726,"owners_count":17275477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ggplot2","r","r-package","uncertainty","uncertainty-visualization","visualization"],"created_at":"2024-08-02T23:01:06.040Z","updated_at":"2025-05-06T20:32:34.981Z","avatar_url":"https://github.com/mjskay.png","language":"R","funding_links":[],"categories":["Plot layers"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n```{r chunk_options, include=FALSE}\nknitr::opts_chunk$set(\n  fig.path = \"man/figures/README/\"\n)\nknitr::opts_chunk$set(\n  fig.retina = 2\n)\nif (requireNamespace(\"ragg\", quietly = TRUE)) {\n  knitr::opts_chunk$set(\n    dev = \"ragg_png\"\n  )\n} else if (capabilities(\"cairo\")) {\n  knitr::opts_chunk$set(\n    dev = \"png\",\n    dev.args = list(png = list(type = \"cairo\"))\n  )\n}\n```\n\n# ggdist: Visualizations of distributions and uncertainty\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/mjskay/ggdist/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mjskay/ggdist/actions/workflows/R-CMD-check.yaml)\n[![Coverage status](https://codecov.io/gh/mjskay/ggdist/branch/master/graph/badge.svg)](https://app.codecov.io/github/mjskay/ggdist?branch=master)\n[![CRAN status](https://www.r-pkg.org/badges/version/ggdist)](https://cran.r-project.org/package=ggdist)\n![Download count](https://cranlogs.r-pkg.org/badges/ggdist)\n[![Paper DOI](https://img.shields.io/badge/DOI-10.1109%2FTVCG.2023.3327195-blue\n)](https://doi.org/10.1109/TVCG.2023.3327195)\n[![Software DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3879620.svg)](https://doi.org/10.5281/zenodo.3879620)\n\u003c!-- badges: end --\u003e\n\n```{r setup, include=FALSE}\nlibrary(dplyr)\nlibrary(tidyr)\nlibrary(distributional)\nlibrary(ggdist)\nlibrary(ggplot2)\nlibrary(patchwork)\n\ntheme_set(theme_ggdist())\n```\n\n```{r preview_setup, include=FALSE}\nset.seed(12345)\nd = dist_normal(4, 1)\nd_quantiles = dist_sample(list(qnorm(ppoints(1000), 4, 1)))\nq_100 = qnorm(ppoints(100), 4, 1)\nx_samples_100 = rnorm(100, 4, 1)\nd_samples_100 = dist_sample(list(x_samples_100))\n\ndists_xlim = c(0,8)\n```\n\n```{r preview_slabinterval, include=FALSE}\nslabinterval_plot = ggplot() +\n  stat_halfeye(aes(y = \"01\", xdist = d)) +\n  stat_eye(aes(y = \"02\", xdist = d)) +\n  stat_gradientinterval(aes(y = \"03\", xdist = d), scale = 0.75, fill_type = \"gradient\", show_interval = FALSE, show_point = FALSE, position = position_nudge(y = -0.2)) +\n  stat_ccdfinterval(aes(y = \"04\", xdist = d), scale = .5, justification = 0, position = position_nudge(y = -0.3)) +\n  stat_cdfinterval(aes(y = \"05\", xdist = d), scale = .5, justification = 0, position = position_nudge(y = -0.2)) +\n  stat_interval(\n    aes(y = \"06\", xdist = d), color = \"gray65\", alpha = 1/3, linewidth = 10,\n    position = position_nudge(y = -.1)\n  ) +\n  stat_pointinterval(aes(y = \"07\", xdist = d)) +\n  stat_slab(aes(y = \"08\", xdist = d), position = position_nudge(y = - 0.2)) +\n  stat_histinterval(aes(y = \"09\", xdist = d_quantiles), position = position_nudge(y = - 0.25)) +\n  stat_slab(\n    aes(y = \"10\", xdist = d, fill_ramp = after_stat(level)), \n    show.legend = FALSE, .width = c(.5, .8, .95),\n    fill = scales::brewer_pal()(7)[[5]],\n    position = position_nudge(y = -0.5)    \n  ) +\n  stat_spike(\n    aes(y = \"10\", xdist = d, linetype = after_stat(at)),\n    at = c(mode = Mode, qi = function(...) qi(..., .width = .8)),\n    show.legend = FALSE,\n    position = position_nudge(y = -0.5)\n  ) +\n  scale_x_continuous(limits = dists_xlim, expand = c(0,0), labels = NULL) +\n  scale_y_discrete(limits = rev, labels = NULL) +\n  labs(\n    title = \"slabinterval\",\n    x = NULL,\n    y = NULL\n  ) +\n  theme(plot.margin = margin(5.5, 5.5, 5.5, 0), axis.ticks = element_blank())\n```\n\n```{r preview_dotsinterval, include=FALSE}\nset.seed(123456)\nx1 = rnorm(125, 3, 0.75)\nx2 = rnorm(125, 5, 0.75)\n\ndotsinterval_plot = ggplot() +\n  stat_dotsinterval(aes(y = \"01\", xdist = d)) +\n  stat_dots(aes(y = \"02\", xdist = d), layout = \"weave\", position = position_nudge(y = -0.2)) +\n  geom_weave(aes(y = \"03\", x = x1, fill = x1 \u003e 4, group = NA), linewidth = NA, alpha = 0.75, binwidth = NA) +\n  geom_swarm(aes(y = \"04\", x = x2, fill = x2 \u003e 4, group = NA), linewidth = NA, alpha = 0.75, binwidth = NA, position = position_nudge(y = 0.1)) +\n  scale_fill_brewer(palette = \"Dark2\", guide = \"none\") +\n  \n  ggnewscale::new_scale_fill() +\n  stat_dotsinterval(aes(y = \"05\", xdist = d, fill = after_stat(level)), layout = \"weave\", slab_linewidth = NA, .width = c(.66, .95), quantiles = 200, position = position_nudge(y = -0.3)) +\n  scale_color_manual(values = scales::brewer_pal()(3)[-1], aesthetics = \"fill\", guide = \"none\") +\n  \n  ggnewscale::new_scale_fill() +\n  geom_dots(aes(y = \"06\", x = x1, fill = \"a\"), side = \"bottom\", scale = 0.75, linewidth = NA, position = position_nudge(y = -0.1)) +\n  stat_slabinterval(aes(y = \"06\", x = x1, fill = \"a\"), scale = 0.5, position = position_nudge(y = -0.1)) +\n  geom_dots(aes(y = \"07\", x = x2, fill = \"b\"), side = \"bottom\", scale = 0.75, linewidth = NA, position = position_nudge(y = -0.2)) +\n  stat_slabinterval(aes(y = \"07\", x = x2, fill = \"b\"), scale = 0.5, position = position_nudge(y = -0.2)) +\n  scale_fill_brewer(palette = \"Set2\", guide = \"none\") +\n  \n  \n  scale_x_continuous(limits = dists_xlim, expand = c(0,0), labels = NULL) +\n  scale_y_discrete(limits = rev, labels = NULL) +\n  labs(\n    title = \"dotsinterval\",\n    x = NULL,\n    y = NULL\n  ) +\n  theme(axis.ticks = element_blank())\n```\n\n```{r preview_lineribbon, include=FALSE}\nm_mpg = lm(mpg ~ hp * cyl, data = mtcars)\nmtcars_preds = mtcars %\u003e%\n  group_by(cyl) %\u003e%\n  expand(hp = seq(min(hp), max(hp), length.out = 50)) %\u003e%\n  bind_cols(predict(m_mpg, newdata = ., se.fit = TRUE))\n\nmtcars_plot = function(.width = c(.5, .8, .95), alpha = 1/4, ...) {\n  mtcars_preds %\u003e%\n    ggplot(aes(x = hp, fill = ordered(cyl), color = ordered(cyl))) +\n    stat_lineribbon(\n      aes(ydist = dist_student_t(df, fit, se.fit)), \n      .width = .width, alpha = alpha, ...\n    ) +\n    geom_point(aes(y = mpg), data = mtcars) +\n    \n    scale_fill_brewer(palette = \"Set2\") +\n    scale_color_brewer(palette = \"Dark2\") +\n    labs(\n      color = \"cyl\",\n      fill = \"cyl\",\n      y = \"mpg\"\n    ) +\n    theme_ggdist()\n}\n\nlineribbon_plot_1 = mtcars_plot() +\n  guides(color = \"none\", fill = \"none\", x = \"none\") +\n  scale_x_continuous(labels = NULL) +\n  scale_y_continuous(labels = NULL) +\n  labs(title = \"lineribbon\", x = NULL, y = NULL) +\n  theme(plot.margin = margin(5.5, 5.5, 0, 5.5), axis.ticks = element_blank())\nlineribbon_plot_2 = mtcars_plot(.width = ppoints(30), alpha = 1/20) +\n  guides(color = \"none\", fill = \"none\") +\n  scale_x_continuous(labels = NULL) +\n  scale_y_continuous(labels = NULL) +\n  labs(x = NULL, y = NULL) +\n  theme(plot.margin = margin(0, 5.5, 5.5, 5.5), axis.ticks = element_blank())\n```\n\n```{r preview, echo=FALSE, fig.height=4.5, fig.width=9}\nslabinterval_plot + dotsinterval_plot + (lineribbon_plot_1 / lineribbon_plot_2) +\n  plot_annotation(\n    caption = 'Some examples from the three main families of ggdist geometries'\n  )\n```\n\n[ggdist](https://mjskay.github.io/ggdist/) is an R package that provides a flexible set of `{ggplot2}` geoms and stats designed\nespecially for visualizing distributions and uncertainty. It is designed for both\nfrequentist and Bayesian uncertainty visualization, taking the view that uncertainty\nvisualization can be unified through the perspective of distribution visualization:\nfor frequentist models, one visualizes confidence distributions or bootstrap distributions (see `vignette(\"freq-uncertainty-vis\")`);\nfor Bayesian models, one visualizes probability distributions (see the [tidybayes](https://mjskay.github.io/tidybayes/) \npackage, which builds on top of `{ggdist}`).\n\nThe `geom_slabinterval()` / `stat_slabinterval()` family (see `vignette(\"slabinterval\")`) makes it\neasy to visualize point summaries and intervals, eye plots, half-eye plots, ridge plots,\nCCDF bar plots, gradient plots, histograms, and more:\n\n\u003cimg src=\"man/figures/slabinterval_family.png\" alt=\"The slabinterval family of geoms and stats\"\u003e\n\nThe `geom_dotsinterval()` / `stat_dotsinterval()` family (see `vignette(\"dotsinterval\")`) makes\nit easy to visualize dot+interval plots, Wilkinson dotplots, beeswarm plots, and quantile dotplots\n(and combined with half-eyes, composite plots like rain cloud plots):\n\n```{r halfeye_dotplot, echo=FALSE, message=FALSE, warning=FALSE}\nset.seed(12345) # for reproducibility\n\ndata.frame(\n  abc = c(\"a\", \"b\", \"c\"),\n  value = rnorm(300, c(1, 8, 3), c(1, 1.7, 1))\n) %\u003e%\n  ggplot(aes(y = abc, x = value, fill = abc)) +\n  geom_dots(layout = \"weave\", side = \"bottom\", linewidth = 0) +\n  stat_slabinterval() +\n  scale_fill_brewer(palette = \"Set2\") +\n  theme_ggdist() +\n  labs(\n    title = \"Rainclouds using geom_dots(layout = 'weave') with stat_slabinterval()\"\n  )\n```\n\nThe `geom_lineribbon()` / `stat_lineribbon()` family (see `vignette(\"lineribbon\")`) makes it easy to visualize \nfit lines with an arbitrary number of uncertainty bands:\n  \n```{r lineribbon, echo=FALSE, message=FALSE, warning=FALSE}\nmtcars_plot()\n```\n\nAll stats in `{ggdist}` also support visualizing analytical distributions and vectorized distribution\ndata types like [distributional](https://pkg.mitchelloharawild.com/distributional/) objects or `posterior::rvar()` \nobjects. This is particularly useful when visualizing uncertainty in frequentist\nmodels (see `vignette(\"freq-uncertainty-vis\")`) or when visualizing priors in a\nBayesian analysis.\n\nThe `{ggdist}` geoms and stats also form a core part of the [tidybayes](https://mjskay.github.io/tidybayes/) package (in fact,\nthey originally were part of `{tidybayes}`). For examples of the use of `{ggdist}` geoms and\nstats for visualizing uncertainty in Bayesian models, see the vignettes in `{tidybayes}`, such as\n`vignette(\"tidybayes\", package = \"tidybayes\")` or `vignette(\"tidy-brms\", package = \"tidybayes\")`.\n\n## Cheat sheets\n\nThese cheat sheets focus on the `slabinterval` family of geometries:\n\n\u003ca href=\"https://github.com/mjskay/ggdist/blob/master/figures-source/cheat_sheet-slabinterval.pdf\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/mjskay/ggdist/master/figures-source/cheat_sheet-slabinterval.png\" width=\"630\" /\u003e\u003c/a\u003e  \n\n## Installation\n\nYou can install the currently-released version from CRAN with this R\ncommand:\n\n```{r install, eval=FALSE}\ninstall.packages(\"ggdist\")\n```\n\nAlternatively, you can install the latest development version from GitHub with these R\ncommands:\n\n```{r install_github, eval=FALSE}\ninstall.packages(\"devtools\")\ndevtools::install_github(\"mjskay/ggdist\")\n```\n\n## Dependencies\n\n`{ggdist}` aims to have minimal additional dependencies beyond those already\nrequired by `{ggplot2}`. The `{ggdist}` dependencies fall into the following \ncategories:\n\n1. `{ggplot2}`.\n\n2. Packages that `{ggplot2}` also depends on. These packages add no additional\ndependency cost because `{ggplot2}` already requires them: `{rlang}`, `{cli}`, \n`{scales}`, `{tibble}`, `{vctrs}`, `{withr}`, `{gtable}`, and `{glue}`.\n\n3. Packages that `{ggplot2}` does not depend on. These are all well-maintained \npackages with few dependencies and a clear need within `{ggdist}`:\n   - `{distributional}`: this implementation of distribution vectors powers\n     much of `{ggdist}`. This package adds minimal additional cost, as its only\n     dependency that is not also a dependency of `{ggplot2}` is `{numDeriv}`, which\n     is needed by `{ggdist}` anyway (see below).\n   - `{numDeriv}`: used for calculating Jacobians of scale transformations. \n     Needed because testing has revealed common situations where \n     `stats::numericDeriv()` fails but `{numDeriv}` does not. Widely used by other\n     CRAN packages and has no additional dependencies.\n   - `{quadprog}`: Used to solve constrained optimization problems during different\n     parts of dotplot layout, particularly to avoid dot overlaps in the `\"bin\"`\n     and `\"weave\"` layouts. Widely used by other CRAN packages and has no \n     additional dependencies.\n   - `{Rcpp}`: Used to implement faster dotplot layout. Widely used by other CRAN\n     packages and has no additional dependencies.\n\n## Feedback, issues, and contributions\n\nI welcome feedback, suggestions, issues, and contributions! If you have found a bug, please file it [here](https://github.com/mjskay/ggdist/issues/new) with minimal code to reproduce the issue. Pull requests should be filed against the [`dev`](https://github.com/mjskay/ggdist/tree/dev) branch. I am not particularly reliable over email, though you can try to contact me at \u003cmjskay@northwestern.edu\u003e. A [Bluesky](https://bsky.app/) message is more likely to elicit a response.\n\n## Citing `ggdist`\n\nMatthew Kay (2024). ggdist: Visualizations of Distributions and Uncertainty in the Grammar of Graphics. _IEEE Transactions on Visualization and Computer Graphics_, 30(1), 414--424. DOI: [10.1109/TVCG.2023.3327195](https://doi.org/10.1109/TVCG.2023.3327195).\n\nMatthew Kay (`r format(Sys.Date(), \"%Y\")`). ggdist: Visualizations of Distributions and Uncertainty. R package version `r getNamespaceVersion(\"ggdist\")`, \u003chttps://mjskay.github.io/ggdist/\u003e. DOI: [10.5281/zenodo.3879620](https://doi.org/10.5281/zenodo.3879620).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/mjskay.github.io%2Fggdist%2F","html_url":"https://awesome.ecosyste.ms/projects/mjskay.github.io%2Fggdist%2F","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/mjskay.github.io%2Fggdist%2F/lists"}