{"id":13586786,"url":"https://github.com/IndrajeetPatil/ggstatsplot","last_synced_at":"2025-04-07T18:35:05.918Z","repository":{"id":37839334,"uuid":"116717490","full_name":"IndrajeetPatil/ggstatsplot","owner":"IndrajeetPatil","description":"Enhancing {ggplot2} plots with statistical analysis 📊📣","archived":false,"fork":false,"pushed_at":"2025-03-31T22:10:43.000Z","size":2342231,"stargazers_count":2083,"open_issues_count":68,"forks_count":199,"subscribers_count":43,"default_branch":"main","last_synced_at":"2025-04-02T00:08:38.352Z","etag":null,"topics":["bayes-factors","datascience","dataviz","effect-size","ggplot-extension","hypothesis-testing","non-parametric-statistics","r","regression-models","statistical-analysis"],"latest_commit_sha":null,"homepage":"https://indrajeetpatil.github.io/ggstatsplot/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IndrajeetPatil.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":".github/CODEOWNERS.txt","security":null,"support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json"},"funding":{"github":"easystats"}},"created_at":"2018-01-08T19:16:42.000Z","updated_at":"2025-03-28T07:05:18.000Z","dependencies_parsed_at":"2024-01-17T13:10:38.407Z","dependency_job_id":"f5e65903-9967-4cff-bd09-17add9baf49f","html_url":"https://github.com/IndrajeetPatil/ggstatsplot","commit_stats":{"total_commits":1805,"total_committers":12,"mean_commits":"150.41666666666666","dds":"0.22382271468144044","last_synced_commit":"b5aef0e2f025ecf231dea4a6a8ffd47a1c33a2fa"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndrajeetPatil%2Fggstatsplot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndrajeetPatil%2Fggstatsplot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndrajeetPatil%2Fggstatsplot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndrajeetPatil%2Fggstatsplot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IndrajeetPatil","download_url":"https://codeload.github.com/IndrajeetPatil/ggstatsplot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247707833,"owners_count":20982857,"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":["bayes-factors","datascience","dataviz","effect-size","ggplot-extension","hypothesis-testing","non-parametric-statistics","r","regression-models","statistical-analysis"],"created_at":"2024-08-01T15:05:48.594Z","updated_at":"2025-04-07T18:35:05.907Z","avatar_url":"https://github.com/IndrajeetPatil.png","language":"R","readme":"---\noutput: github_document\n---\n\n  \u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r}\n#| echo = FALSE,\n#| warning = FALSE,\n#| message = FALSE\n## show me all columns\noptions(\n  tibble.width      = Inf,\n  pillar.bold       = TRUE,\n  pillar.neg        = TRUE,\n  pillar.subtle_num = TRUE,\n  pillar.min_chars  = Inf\n)\n\nknitr::opts_chunk$set(\n  collapse  = TRUE,\n  dpi       = 150, ## change to 300 once on CRAN\n  warning   = FALSE,\n  message   = FALSE,\n  out.width = \"100%\",\n  comment   = \"#\u003e\",\n  fig.path  = \"man/figures/README-\"\n)\n\nlibrary(ggstatsplot)\n```\n\n## `{ggstatsplot}`: `{ggplot2}` Based Plots with Statistical Details \n\nStatus | Usage | Miscellaneous\n----------------- | ----------------- | ----------------- \n[![R build status](https://github.com/IndrajeetPatil/ggstatsplot/workflows/R-CMD-check/badge.svg)](https://github.com/IndrajeetPatil/ggstatsplot) | [![Total downloads](https://cranlogs.r-pkg.org/badges/grand-total/ggstatsplot?color=blue)](https://CRAN.R-project.org/package=ggstatsplot) | [![codecov](https://codecov.io/gh/IndrajeetPatil/ggstatsplot/branch/main/graph/badge.svg?token=ddrxwt0bj8)](https://app.codecov.io/gh/IndrajeetPatil/ggstatsplot)\n[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html) | [![Daily downloads](https://cranlogs.r-pkg.org/badges/last-day/ggstatsplot?color=blue)](https://CRAN.R-project.org/package=ggstatsplot) | [![DOI](https://joss.theoj.org/papers/10.21105/joss.03167/status.svg)](https://doi.org/10.21105/joss.03167)\n\n## Raison d'être \u003cimg src=\"man/figures/logo.png\" align=\"right\" width=\"360\" /\u003e\n\n\u003e \"What is to be sought in designs for the display of information is the clear\nportrayal of complexity. Not the complication of the simple; rather ... the\nrevelation of the complex.\"\n- Edward R. Tufte\n\n[`{ggstatsplot}`](https://indrajeetpatil.github.io/ggstatsplot/) is an extension\nof [`{ggplot2}`](https://github.com/tidyverse/ggplot2) package for creating\ngraphics with details from statistical tests included in the information-rich\nplots themselves. In a typical exploratory data analysis workflow, data\nvisualization and statistical modeling are two different phases: visualization\ninforms modeling, and modeling in its turn can suggest a different visualization\nmethod, and so on and so forth. The central idea of `{ggstatsplot}` is simple:\ncombine these two phases into one in the form of graphics with statistical\ndetails, which makes data exploration simpler and faster.\n\n## Installation\n\n| Type        | Command                                  |\n| :---------- | :--------------------------------------- |\n| Release     | `install.packages(\"ggstatsplot\")`        |\n| Development | `pak::pak(\"IndrajeetPatil/ggstatsplot\")` |\n\n## Citation\n\nIf you want to cite this package in a scientific journal or in any other\ncontext, run the following code in your `R` console:\n\n```{r}\n#| label = \"citation\",\n#| comment = \"\"\ncitation(\"ggstatsplot\")\n```\n\n## Acknowledgments\n\nI would like to thank all the contributors to `{ggstatsplot}` who pointed out\nbugs or requested features I hadn't considered. I would especially like to thank\nother package developers (especially Daniel Lüdecke, Dominique Makowski, Mattan\nS. Ben-Shachar, Brenton Wiernik, Patrick Mair, Salvatore Mangiafico, etc.) who\nhave patiently and diligently answered my relentless questions and supported\nfeature requests in their projects. I also want to thank Chuck Powell for his\ninitial contributions to the package.\n\nThe hexsticker was generously designed by Sarah Otterstetter (Max Planck\nInstitute for Human Development, Berlin). This package has also benefited from\nthe larger `#rstats` community on Twitter, LinkedIn, and `StackOverflow`.\n\nThanks are also due to my postdoc advisers (Mina Cikara and Fiery Cushman at\nHarvard University; Iyad Rahwan at Max Planck Institute for Human Development)\nwho patiently supported me spending hundreds (?) of hours working on this\npackage rather than what I was paid to do. 😁\n\n## Documentation and Examples\n\nTo see the detailed documentation for each function in the stable **CRAN**\nversion of the package, see:\n\n  - [Publication](https://joss.theoj.org/papers/10.21105/joss.03167)\n\n  - [Presentation](https://indrajeetpatil.github.io/intro-to-ggstatsplot/#/ggstatsplot-informative-statistical-visualizations)\n  \n  - [Vignettes](https://indrajeetpatil.github.io/ggstatsplot/articles/)\n\n## Summary of available plots\n\n| Function           | Plot                      | Description                                     |\n| :----------------- | :------------------------ | :---------------------------------------------- |\n| `ggbetweenstats()` | **violin plots**          | for comparisons *between* groups/conditions     |\n| `ggwithinstats()`  | **violin plots**          | for comparisons *within* groups/conditions      |\n| `gghistostats()`   | **histograms**            | for distribution about numeric variable         |\n| `ggdotplotstats()` | **dot plots/charts**      | for distribution about labeled numeric variable |\n| `ggscatterstats()` | **scatterplots**          | for correlation between two variables           |\n| `ggcorrmat()`      | **correlation matrices**  | for correlations between multiple variables     |\n| `ggpiestats()`     | **pie charts**            | for categorical data                            |\n| `ggbarstats()`     | **bar charts**            | for categorical data                            |\n| `ggcoefstats()`    | **dot-and-whisker plots** | for regression models and meta-analysis         |\n\nIn addition to these basic plots, `{ggstatsplot}` also provides **`grouped_`**\nversions (see below) that makes it easy to repeat the same analysis for\nany grouping variable.\n\n## Summary of types of statistical analyses\n\nThe table below summarizes all the different types of analyses currently\nsupported in this package-\n\n| Functions                            | Description                                       | Parametric | Non-parametric | Robust | Bayesian |\n| :----------------------------------- | :------------------------------------------------ | :--------- | :------------- | :----- | :------- |\n| `ggbetweenstats()`                   | Between group/condition comparisons               | ✅         | ✅             | ✅     | ✅       |\n| `ggwithinstats()`                    | Within group/condition comparisons                | ✅         | ✅             | ✅     | ✅       |\n| `gghistostats()`, `ggdotplotstats()` | Distribution of a numeric variable                | ✅         | ✅             | ✅     | ✅       |\n| `ggcorrmat`                          | Correlation matrix                                | ✅         | ✅             | ✅     | ✅       |\n| `ggscatterstats()`                   | Correlation between two variables                 | ✅         | ✅             | ✅     | ✅       |\n| `ggpiestats()`, `ggbarstats()`       | Association between categorical variables         | ✅         | ✅             | ❌     | ✅       |\n| `ggpiestats()`, `ggbarstats()`       | Equal proportions for categorical variable levels | ✅         | ✅             | ❌     | ✅       |\n| `ggcoefstats()`                      | Regression model coefficients                     | ✅         | ✅             | ✅     | ✅       |\n| `ggcoefstats()`                      | Random-effects meta-analysis                      | ✅         | ❌             | ✅     | ✅       |\n\nSummary of Bayesian analysis\n\n| Analysis                        | Hypothesis testing | Estimation |\n| :------------------------------ | :----------------- | :--------- |\n| (one/two-sample) *t*-test       | ✅                 | ✅         |\n| one-way ANOVA                   | ✅                 | ✅         |\n| correlation                     | ✅                 | ✅         |\n| (one/two-way) contingency table | ✅                 | ✅         |\n| random-effects meta-analysis    | ✅                 | ✅         |\n\n## Statistical reporting\n\nFor **all** statistical tests reported in the plots, the default template abides\nby the gold standard for statistical reporting. For example, here are results\nfrom Yuen's test for trimmed means (robust *t*-test):\n\n\u003cimg src=\"man/figures/stats_reporting_format.png\" align=\"center\" /\u003e\n\n## Summary of statistical tests and effect sizes\n\nStatistical analysis is carried out by `{statsExpressions}` package, and thus\na summary table of all the statistical tests currently supported across\nvarious functions can be found in article for that package:\n\u003chttps://indrajeetpatil.github.io/statsExpressions/articles/stats_details.html\u003e\n\n## Primary functions\n\n### `ggbetweenstats()`\n\nThis function creates either a violin plot, a box plot, or a mix of two for\n**between**-group or **between**-condition comparisons with results from\nstatistical tests in the subtitle. The simplest function call looks like this-\n\n```{r}\n#| label = \"ggbetweenstats1\"\nset.seed(123)\n\nggbetweenstats(\n  data  = iris,\n  x     = Species,\n  y     = Sepal.Length,\n  title = \"Distribution of sepal length across Iris species\"\n)\n```\n\n**Defaults** return\u003cbr\u003e\n\n✅ raw data + distributions \u003cbr\u003e\n✅ descriptive statistics \u003cbr\u003e\n✅ inferential statistics \u003cbr\u003e\n✅ effect size + CIs \u003cbr\u003e\n✅ pairwise comparisons \u003cbr\u003e\n✅ Bayesian hypothesis-testing \u003cbr\u003e\n✅ Bayesian estimation \u003cbr\u003e\n\nA number of other arguments can be specified to make this plot even more\ninformative or change some of the default options. Additionally, there is also a\n`grouped_` variant of this function that makes it easy to repeat the same\noperation across a **single** grouping variable:\n\n```{r}\n#| label = \"ggbetweenstats2\",\n#| fig.height = 8,\n#| fig.width = 12\nset.seed(123)\n\ngrouped_ggbetweenstats(\n  data             = dplyr::filter(movies_long, genre %in% c(\"Action\", \"Comedy\")),\n  x                = mpaa,\n  y                = length,\n  grouping.var     = genre,\n  ggsignif.args    = list(textsize = 4, tip_length = 0.01),\n  p.adjust.method  = \"bonferroni\",\n  palette          = \"default_jama\",\n  package          = \"ggsci\",\n  plotgrid.args    = list(nrow = 1),\n  annotation.args  = list(title = \"Differences in movie length by mpaa ratings for different genres\")\n)\n```\n\nDetails about underlying functions used to create graphics and statistical tests carried out can be found in the function documentation:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/reference/ggbetweenstats.html\u003e\n\nFor more, also read the following vignette:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggbetweenstats.html\u003e\n\n### `ggwithinstats()`\n\n`ggbetweenstats()` function has an identical twin function `ggwithinstats()` for\nrepeated measures designs that behaves in the same fashion with a few minor\ntweaks introduced to properly visualize the repeated measures design. As can be\nseen from an example below, the only difference between the plot structure is\nthat now the group means are connected by paths to highlight the fact that these\ndata are paired with each other.\n\n```{r}\n#| label = \"ggwithinstats1\",\n#| fig.width = 8,\n#| fig.height = 6\nset.seed(123)\nlibrary(WRS2) ## for data\nlibrary(afex) ## to run ANOVA\n\nggwithinstats(\n  data    = WineTasting,\n  x       = Wine,\n  y       = Taste,\n  title   = \"Wine tasting\"\n)\n```\n\n**Defaults** return\u003cbr\u003e\n\n✅ raw data + distributions \u003cbr\u003e\n✅ descriptive statistics \u003cbr\u003e\n✅ inferential statistics \u003cbr\u003e\n✅ effect size + CIs \u003cbr\u003e\n✅ pairwise comparisons \u003cbr\u003e\n✅ Bayesian hypothesis-testing \u003cbr\u003e\n✅ Bayesian estimation \u003cbr\u003e\n\nAs with the `ggbetweenstats()`, this function also has a `grouped_` variant that\nmakes repeating the same analysis across a single grouping variable quicker. We\nwill see an example with only repeated measurements-\n\n```{r}\n#| label = \"ggwithinstats2\",\n#| fig.height = 6,\n#| fig.width = 14\nset.seed(123)\n\ngrouped_ggwithinstats(\n  data            = dplyr::filter(bugs_long, region %in% c(\"Europe\", \"North America\"), condition %in% c(\"LDLF\", \"LDHF\")),\n  x               = condition,\n  y               = desire,\n  type            = \"np\",\n  xlab            = \"Condition\",\n  ylab            = \"Desire to kill an artrhopod\",\n  grouping.var    = region\n)\n```\n\nDetails about underlying functions used to create graphics and statistical tests carried out can be found in the function documentation:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/reference/ggwithinstats.html\u003e\n\nFor more, also read the following vignette:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggwithinstats.html\u003e\n\n### `gghistostats()`\n\nTo visualize the distribution of a single variable and check if its mean is\nsignificantly different from a specified value with a one-sample test,\n`gghistostats()` can be used.\n\n```{r}\n#| label = \"gghistostats1\",\n#| fig.width = 8\nset.seed(123)\n\ngghistostats(\n  data       = ggplot2::msleep,\n  x          = awake,\n  title      = \"Amount of time spent awake\",\n  test.value = 12,\n  binwidth   = 1\n)\n```\n\n**Defaults** return\u003cbr\u003e\n\n✅ counts + proportion for bins\u003cbr\u003e\n✅ descriptive statistics \u003cbr\u003e\n✅ inferential statistics \u003cbr\u003e\n✅ effect size + CIs \u003cbr\u003e\n✅ Bayesian hypothesis-testing \u003cbr\u003e\n✅ Bayesian estimation \u003cbr\u003e\n\nThere is also a `grouped_` variant of this function that makes it\neasy to repeat the same operation across a **single** grouping variable:\n\n```{r}\n#| label = \"gghistostats2\",\n#| fig.height = 6,\n#| fig.width = 12\nset.seed(123)\n\ngrouped_gghistostats(\n  data              = dplyr::filter(movies_long, genre %in% c(\"Action\", \"Comedy\")),\n  x                 = budget,\n  test.value        = 50,\n  type              = \"nonparametric\",\n  xlab              = \"Movies budget (in million US$)\",\n  grouping.var      = genre,\n  ggtheme           = ggthemes::theme_tufte(),\n  ## modify the defaults from `{ggstatsplot}` for each plot\n  plotgrid.args     = list(nrow = 1),\n  annotation.args   = list(title = \"Movies budgets for different genres\")\n)\n```\n\nDetails about underlying functions used to create graphics and statistical tests carried out can be found in the function documentation:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/reference/gghistostats.html\u003e\n\nFor more, also read the following vignette:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/articles/web_only/gghistostats.html\u003e\n\n### `ggdotplotstats()`\n\nThis function is similar to `gghistostats()`, but is intended to be used when the\nnumeric variable also has a label.\n\n```{r}\n#| label = \"ggdotplotstats1\",\n#| fig.height = 10,\n#| fig.width = 8\nset.seed(123)\n\nggdotplotstats(\n  data       = dplyr::filter(gapminder::gapminder, continent == \"Asia\"),\n  y          = country,\n  x          = lifeExp,\n  test.value = 55,\n  type       = \"robust\",\n  title      = \"Distribution of life expectancy in Asian continent\",\n  xlab       = \"Life expectancy\"\n)\n```\n\n**Defaults** return\u003cbr\u003e\n\n✅ descriptives (mean + sample size) \u003cbr\u003e\n✅ inferential statistics \u003cbr\u003e\n✅ effect size + CIs \u003cbr\u003e\n✅ Bayesian hypothesis-testing \u003cbr\u003e\n✅ Bayesian estimation \u003cbr\u003e\n\nAs with the rest of the functions in this package, there is also a `grouped_`\nvariant of this function to facilitate looping the same operation for all levels\nof a single grouping variable.\n\n```{r}\n#| label = \"ggdotplotstats2\",\n#| fig.height = 6,\n#| fig.width = 12\nset.seed(123)\n\ngrouped_ggdotplotstats(\n  data            = dplyr::filter(ggplot2::mpg, cyl %in% c(\"4\", \"6\")),\n  x               = cty,\n  y               = manufacturer,\n  type            = \"bayes\",\n  xlab            = \"city miles per gallon\",\n  ylab            = \"car manufacturer\",\n  grouping.var    = cyl,\n  test.value      = 15.5,\n  point.args      = list(color = \"red\", size = 5, shape = 13),\n  annotation.args = list(title = \"Fuel economy data\")\n)\n```\n\nDetails about underlying functions used to create graphics and statistical tests carried out can be found in the function documentation:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/reference/ggdotplotstats.html\u003e\n\nFor more, also read the following vignette:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggdotplotstats.html\u003e\n\n### `ggscatterstats()`\n\nThis function creates a scatterplot with marginal distributions overlaid on the\naxes and results from statistical tests in the subtitle:\n\n```{r}\n#| label = \"ggscatterstats1\",\n#| fig.height = 6\nggscatterstats(\n  data  = ggplot2::msleep,\n  x     = sleep_rem,\n  y     = awake,\n  xlab  = \"REM sleep (in hours)\",\n  ylab  = \"Amount of time spent awake (in hours)\",\n  title = \"Understanding mammalian sleep\"\n)\n```\n\n**Defaults** return\u003cbr\u003e\n\n✅ raw data + distributions \u003cbr\u003e\n✅ marginal distributions \u003cbr\u003e\n✅ inferential statistics \u003cbr\u003e\n✅ effect size + CIs \u003cbr\u003e\n✅ Bayesian hypothesis-testing \u003cbr\u003e\n✅ Bayesian estimation \u003cbr\u003e\n\nThere is also a `grouped_` variant of this function that makes it\neasy to repeat the same operation across a **single** grouping variable.\n\n```{r}\n#| label = \"ggscatterstats2\",\n#| fig.height = 8,\n#| fig.width = 14\nset.seed(123)\n\ngrouped_ggscatterstats(\n  data             = dplyr::filter(movies_long, genre %in% c(\"Action\", \"Comedy\")),\n  x                = rating,\n  y                = length,\n  grouping.var     = genre,\n  label.var        = title,\n  label.expression = length \u003e 200,\n  xlab             = \"IMDB rating\",\n  ggtheme          = ggplot2::theme_grey(),\n  ggplot.component = list(ggplot2::scale_x_continuous(breaks = seq(2, 9, 1), limits = (c(2, 9)))),\n  plotgrid.args    = list(nrow = 1),\n  annotation.args  = list(title = \"Relationship between movie length and IMDB ratings\")\n)\n```\n\nDetails about underlying functions used to create graphics and statistical tests carried out can be found in the function documentation:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/reference/ggscatterstats.html\u003e\n\nFor more, also read the following vignette:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggscatterstats.html\u003e\n\n### `ggcorrmat`\n\n`ggcorrmat` makes a correlalogram (a matrix of correlation coefficients) with\nminimal amount of code. Just sticking to the defaults itself produces\npublication-ready correlation matrices. But, for the sake of exploring the\navailable options, let's change some of the defaults. For example, multiple\naesthetics-related arguments can be modified to change the appearance of the\ncorrelation matrix.\n\n```{r}\n#| label = \"ggcorrmat1\"\nset.seed(123)\n\n## as a default this function outputs a correlation matrix plot\nggcorrmat(\n  data     = ggplot2::msleep,\n  colors   = c(\"#B2182B\", \"white\", \"#4D4D4D\"),\n  title    = \"Correlalogram for mammals sleep dataset\",\n  subtitle = \"sleep units: hours; weight units: kilograms\"\n)\n```\n\n**Defaults** return\u003cbr\u003e\n\n✅ effect size + significance\u003cbr\u003e\n✅ careful handling of `NA`s\n\nIf there are `NA`s present in the selected variables, the legend will display\nminimum, median, and maximum number of pairs used for correlation tests.\n\nThere is also a `grouped_` variant of this function that makes it\neasy to repeat the same operation across a **single** grouping variable:\n\n```{r}\n#| label = \"ggcorrmat2\",\n#| fig.height = 6,\n#| fig.width = 10\nset.seed(123)\n\ngrouped_ggcorrmat(\n  data         = dplyr::filter(movies_long, genre %in% c(\"Action\", \"Comedy\")),\n  type         = \"robust\",\n  colors       = c(\"#cbac43\", \"white\", \"#550000\"),\n  grouping.var = genre,\n  matrix.type  = \"lower\"\n)\n```\n\nDetails about underlying functions used to create graphics and statistical tests carried out can be found in the function documentation:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/reference/ggcorrmat.html\u003e\n\nFor more, also read the following vignette:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggcorrmat.html\u003e\n\n### `ggpiestats()`\n\nThis function creates a pie chart for categorical or nominal variables with\nresults from contingency table analysis (Pearson's chi-squared test for\nbetween-subjects design and McNemar's chi-squared test for within-subjects\ndesign) included in the subtitle of the plot. If only one categorical variable\nis entered, results from one-sample proportion test (i.e., a chi-squared\ngoodness of fit test) will be displayed as a subtitle.\n\nTo study an interaction between two categorical variables:\n\n```{r}\n#| label = \"ggpiestats1\",\n#| fig.height = 4,\n#| fig.width = 8\nset.seed(123)\n\nggpiestats(\n  data         = mtcars,\n  x            = am,\n  y            = cyl,\n  package      = \"wesanderson\",\n  palette      = \"Royal1\",\n  title        = \"Dataset: Motor Trend Car Road Tests\",\n  legend.title = \"Transmission\"\n)\n```\n\n**Defaults** return\u003cbr\u003e\n\n✅ descriptives (frequency + %s) \u003cbr\u003e\n✅ inferential statistics \u003cbr\u003e\n✅ effect size + CIs \u003cbr\u003e\n✅ Goodness-of-fit tests \u003cbr\u003e\n✅ Bayesian hypothesis-testing \u003cbr\u003e\n✅ Bayesian estimation \u003cbr\u003e\n\nThere is also a `grouped_` variant of this function that makes it\neasy to repeat the same operation across a **single** grouping variable.\nFollowing example is a case where the theoretical question is about proportions\nfor different levels of a single nominal variable:\n\n```{r}\n#| label = \"ggpiestats2\",\n#| fig.height = 6,\n#| fig.width = 10\nset.seed(123)\n\ngrouped_ggpiestats(\n  data         = mtcars,\n  x            = cyl,\n  grouping.var = am,\n  label.repel  = TRUE,\n  package      = \"ggsci\",\n  palette      = \"default_ucscgb\"\n)\n```\n\nDetails about underlying functions used to create graphics and statistical tests carried out can be found in the function documentation:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/reference/ggpiestats.html\u003e\n\nFor more, also read the following vignette:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggpiestats.html\u003e\n\n### `ggbarstats()`\n\nIn case you are not a fan of pie charts (for very good reasons), you can\nalternatively use `ggbarstats()` function which has a similar syntax.\n\nN.B. The *p*-values from one-sample proportion test are displayed on top of each\nbar.\n\n```{r}\n#| label = \"ggbarstats1\",\n#| fig.height = 8,\n#| fig.width = 10\nset.seed(123)\nlibrary(ggplot2)\n\nggbarstats(\n  data             = movies_long,\n  x                = mpaa,\n  y                = genre,\n  title            = \"MPAA Ratings by Genre\",\n  xlab             = \"movie genre\",\n  legend.title     = \"MPAA rating\",\n  ggplot.component = list(ggplot2::scale_x_discrete(guide = ggplot2::guide_axis(n.dodge = 2))),\n  palette          = \"Set2\"\n)\n```\n\n**Defaults** return\u003cbr\u003e\n\n✅ descriptives (frequency + %s) \u003cbr\u003e\n✅ inferential statistics \u003cbr\u003e\n✅ effect size + CIs \u003cbr\u003e\n✅ Goodness-of-fit tests \u003cbr\u003e\n✅ Bayesian hypothesis-testing \u003cbr\u003e\n✅ Bayesian estimation \u003cbr\u003e\n\nAnd, needless to say, there is also a `grouped_` variant of this function-\n\n```{r}\n#| label = \"ggbarstats2\",\n#| fig.height = 6,\n#| fig.width = 12\n## setup\nset.seed(123)\n\ngrouped_ggbarstats(\n  data         = mtcars,\n  x            = am,\n  y            = cyl,\n  grouping.var = vs,\n  package      = \"wesanderson\",\n  palette      = \"Darjeeling2\" # ,\n  # ggtheme      = ggthemes::theme_tufte(base_size = 12)\n)\n```\n\nDetails about underlying functions used to create graphics and statistical tests carried out can be found in the function documentation:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/reference/ggbarstats.html\u003e\n\nFor more, also read the following vignette:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggbarstats.html\u003e\n\n### `ggcoefstats()`\n\nThe function `ggcoefstats()` generates **dot-and-whisker plots** for\nregression models. The tidy data frames are prepared\nusing `parameters::model_parameters()`. Additionally, if available, the model\nsummary indices are also extracted from `performance::model_performance()`.\n\n```{r}\n#| label = \"ggcoefstats1\",\n#| fig.height = 5,\n#| fig.width = 6\nset.seed(123)\n\n## model\nmod \u003c- stats::lm(formula = mpg ~ am * cyl, data = mtcars)\n\nggcoefstats(mod)\n```\n\n**Defaults** return\u003cbr\u003e\n\n✅ inferential statistics \u003cbr\u003e\n✅ estimate + CIs \u003cbr\u003e\n✅ model summary (AIC and BIC) \u003cbr\u003e\n\nDetails about underlying functions used to create graphics and statistical tests carried out can be found in the function documentation:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/reference/ggcoefstats.html\u003e\n\nFor more, also read the following vignette:\n\u003chttps://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggcoefstats.html\u003e\n\n### Extracting expressions and data frames with statistical details\n\n`{ggstatsplot}` also offers a convenience function to extract data frames with\nstatistical details that are used to create expressions displayed in\n`{ggstatsplot}` plots.\n\n```{r}\n#| label = \"extract_stats\"\nset.seed(123)\n\np \u003c- ggbetweenstats(mtcars, cyl, mpg)\n\n# extracting expression present in the subtitle\nextract_subtitle(p)\n\n# extracting expression present in the caption\nextract_caption(p)\n\n# a list of tibbles containing statistical analysis summaries\nextract_stats(p)\n```\n\nNote that all of this analysis is carried out by `{statsExpressions}`\npackage: \u003chttps://indrajeetpatil.github.io/statsExpressions/\u003e\n\n### Using `{ggstatsplot}` statistical details with custom plots\n\nSometimes you may not like the default plots produced by `{ggstatsplot}`. In such\ncases, you can use other **custom** plots (from `{ggplot2}` or other plotting\npackages) and still use `{ggstatsplot}` functions to display results from relevant\nstatistical test.\n\nFor example, in the following chunk, we will create our own plot using\n`{ggplot2}` package, and use `{ggstatsplot}` function for extracting expression:\n\n```{r}\n#| label = \"customplot\",\n#| fig.height = 5,\n#| fig.width = 6\n## loading the needed libraries\nset.seed(123)\nlibrary(ggplot2)\n\n## using `{ggstatsplot}` to get expression with statistical results\nstats_results \u003c- ggbetweenstats(morley, Expt, Speed) %\u003e% extract_subtitle()\n\n## creating a custom plot of our choosing\nggplot(morley, aes(x = as.factor(Expt), y = Speed)) +\n  geom_boxplot() +\n  labs(\n    title = \"Michelson-Morley experiments\",\n    subtitle = stats_results,\n    x = \"Speed of light\",\n    y = \"Experiment number\"\n  )\n```\n\n## Summary of benefits of using `{ggstatsplot}`\n\n- No need to use scores of packages for statistical analysis\n  (e.g., one to get stats, one to get effect sizes, another to get Bayes\n  Factors, and yet another to get pairwise comparisons, etc.).\n\n- Minimal amount of code needed for all functions (typically only `data`, `x`,\n  and `y`), which minimizes chances of error and makes for tidy scripts.\n  \n- Conveniently toggle between statistical approaches.\n\n- Truly makes your figures worth a thousand words.\n\n- No need to copy-paste results to the text editor (MS-Word, e.g.).\n\n- Disembodied figures stand on their own and are easy to evaluate for the reader.\n\n- More breathing room for theoretical discussion and other text.\n\n- No need to worry about updating figures and statistical details separately.\n\n## Misconceptions about `{ggstatsplot}`\n\nThis package is... \n\n❌ an alternative to learning `{ggplot2}`\u003cbr\u003e\n✅ (The better you know `{ggplot2}`, the more you can modify the defaults to your\nliking.)\n\n❌ meant to be used in talks/presentations\u003cbr\u003e\n✅ (Default plots can be too complicated for effectively communicating results in\ntime-constrained presentation settings, e.g. conference talks.)\n\n❌ the only game in town\u003cbr\u003e\n✅ (GUI software alternatives: [JASP](https://jasp-stats.org/) and [jamovi](https://www.jamovi.org/)).\n\n## Extensions\n\nIn case you use the GUI software [`jamovi`](https://www.jamovi.org/), you can\ninstall a module called [`jjstatsplot`](https://github.com/sbalci/jjstatsplot),\nwhich is a wrapper around `{ggstatsplot}`.\n\n## Contributing\n\nI'm happy to receive bug reports, suggestions, questions, and (most of all)\ncontributions to fix problems and add features. I personally prefer using the\n`GitHub` issues system over trying to reach out to me in other ways (personal\ne-mail, Twitter, etc.). Pull Requests for contributions are encouraged.\n\nHere are some simple ways in which you can contribute (in the increasing order\nof commitment):\n\n  - Read and correct any inconsistencies in the\n    [documentation](https://indrajeetpatil.github.io/ggstatsplot/)\n  - Raise issues about bugs or wanted features\n  - Review code\n  - Add new functionality (in the form of new plotting functions or helpers for\n    preparing subtitles)\n\nPlease note that this project is released with a \n[Contributor Code of Conduct](https://indrajeetpatil.github.io/ggstatsplot/CODE_OF_CONDUCT.html). By participating in this project you agree to abide by its terms.\n","funding_links":["https://github.com/sponsors/easystats"],"categories":["R","Graphic Displays"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIndrajeetPatil%2Fggstatsplot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FIndrajeetPatil%2Fggstatsplot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIndrajeetPatil%2Fggstatsplot/lists"}