{"id":33187103,"url":"https://hmu-wh.github.io/ggcompare/","last_synced_at":"2025-11-25T18:00:39.124Z","repository":{"id":257807325,"uuid":"861137743","full_name":"HMU-WH/ggcompare","owner":"HMU-WH","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-24T12:37:53.000Z","size":5454,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-22T03:59:01.649Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://hmu-wh.github.io/ggcompare/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HMU-WH.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-09-22T05:15:55.000Z","updated_at":"2025-09-24T12:33:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"a3bad7bb-ce94-4e9d-b7fa-d1fde711ff7e","html_url":"https://github.com/HMU-WH/ggcompare","commit_stats":null,"previous_names":["hmu-wh/ggcompare"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/HMU-WH/ggcompare","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HMU-WH%2Fggcompare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HMU-WH%2Fggcompare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HMU-WH%2Fggcompare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HMU-WH%2Fggcompare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HMU-WH","download_url":"https://codeload.github.com/HMU-WH/ggcompare/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HMU-WH%2Fggcompare/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286079811,"owners_count":27282121,"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","status":"online","status_checked_at":"2025-11-25T02:00:05.816Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-11-16T05:00:30.371Z","updated_at":"2025-11-25T18:00:39.116Z","avatar_url":"https://github.com/HMU-WH.png","language":"R","funding_links":[],"categories":["Data and models"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  dpi = 300,\n  comment = \"#\u003e\",\n  message = FALSE,\n  warning = FALSE,\n  collapse = TRUE,\n  out.width = \"100%\",\n  fig.path = \"man/figures/README-\"\n)\n```\n\n# ggcompare: Mean Comparison in 'ggplot2' \u003ca href=\"https://github.com/HMU-WH/ggcompare\"\u003e \u003cimg src=\"man/figures/README-logo.png\" align=\"right\" height=\"200\" alt=\"\" /\u003e \u003c/a\u003e\n\n[![CRAN status](https://www.r-pkg.org/badges/version/ggcompare)](https://CRAN.R-project.org/package=ggcompare)\n[![R-CMD-check](https://github.com/HMU-WH/ggcompare/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/HMU-WH/ggcompare/actions/workflows/R-CMD-check.yaml)\n[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)\n\n## Introduction\n\nThis package is a subsection extracted from my personal toolkit. \n\nIt was created to improve upon some shortcomings in [`[0.6.4]ggsignif::geom_signif()`](https://github.com/const-ae/ggsignif/) and [`[0.6.0]ggpubr::stat_compare_means()`](https://github.com/kassambara/ggpubr/):\n\n1.  Inability to adapt stably to faceting.\n2.  Inability to perform layer-level P-value adjustment (ggpubr can achieve panel-level adjustment).\n3.  Failure to perform statistical tests smoothly in the absence of some groupings. This is often the cause of poor faceting performance.\n\nUsually you do not need to specify the test method, you only need to tell `stat_compare()` whether you want to perform a parametric test or a nonparametric test, and `stat_compare()` will automatically choose the appropriate test method based on your data. For comparisons between two groups, the p-value is calculated by t-test (parametric) or Wilcoxon rank sum test (nonparametric). For comparisons among more than two groups, the p-value is calculated by One-way ANOVA (parametric) or Kruskal-Wallis test (nonparametric).\n\n## Installation\nYou can install the released version of `ggcompare` from [CRAN](https://CRAN.R-project.org/package=ggcompare) with:\n\n``` r\ninstall.packages(\"ggcompare\")\n```\n\nYou can install the development version of `ggcompare` from [GitHub](https://github.com/HMU-WH/ggcompare/) with:\n\n``` r\n# install.packages(\"devtools\")\ndevtools::install_github(\"HMU-WH/ggcompare\")\n```\n\n## Basic\n\n```{r}\nlibrary(ggplot2)\nlibrary(ggcompare)\n```\n\n```{r include=FALSE}\nlibrary(patchwork)\n```\n\n```{r}\np \u003c- ggplot(mpg, aes(class, displ, color = class)) + \n  geom_boxplot(show.legend = FALSE) + \n  theme_test()\n```\n\n- Global comparison: Each x has only one group.\n\n```{r fig.height=5, fig.width=7}\np + stat_compare()\n```\n\n```{r fig.height=5, fig.width=7}\n# If you just want to display text, you can set parameters \"bracket\" to FALSE.\np + stat_compare(bracket = FALSE)\n```\n\n```{r fig.height=5, fig.width=7}\n# If you want to display the test method, you can do this.\np + stat_compare(aes(label = after_stat(sprintf(\"%s: %s\", method, label))))\n```\n\n- Comparison between two groups: specify a reference group.\n\n```{r fig.height=5, fig.width=7}\np + stat_compare(ref_group = \"minivan\")\n```\n\n```{r fig.height=5, fig.width=7}\n# If you only want to display the p-value less or equal to 0.01, you can do this.\np + stat_compare(ref_group = \"minivan\", cutoff = 0.01)\n```\n\n```{r fig.height=5, fig.width=7}\n# If you want to display the significance level, you can do this.\np + stat_compare(ref_group = \"minivan\", breaks = c(0, 0.001, 0.01, 0.05, 1))\n```\n\n- Comparison between two groups: specify the comparison group.\n\n```{r fig.height=5, fig.width=7}\np + stat_compare(tip_length = 0.05,\n                 step_increase = 0, \n                 comparisons = list(c(\"compact\", \"midsize\"), c(\"pickup\", \"suv\")), \n                 arrow = grid::arrow(type = \"closed\", length = unit(0.1, \"inches\"))) # Yeah, this supports adding arrows.\n```\n\n- Within-group (grouped by the x-axis) population comparison.\n\n```{r fig.height=5, fig.width=7}\nggplot(mpg, aes(drv, displ, fill = class)) +\n  geom_boxplot() +\n  stat_compare() +\n  stat_compare(aes(group = drv), nudge = 0.1, color = \"gray\") + # add global comparison\n  theme_test()\n```\n\n## Enhancement\n\n- Better adaptation to faceting.\n\n```{r}\np \u003c- ggplot(mpg, aes(drv, displ)) +\n  geom_boxplot() +\n  facet_grid(cols = vars(class), scales = \"free\") +\n  theme_test() + \n  theme(plot.title = element_text(size = 20))\n\ncomparisons \u003c- combn(unique(mpg$drv), 2, simplify = FALSE)\n\np1 \u003c- p + stat_compare(comparisons = comparisons) +\n  ggtitle(\"ggcompare::stat_compare\")\n\n# missing test information in some panels\np2 \u003c- p + ggsignif::geom_signif(comparisons = comparisons, step_increase = 0.1) +\n  ggtitle(\"ggsignif::geom_signif\")\n```\n\n```{r echo=FALSE, fig.height=12, fig.width=15}\np1 / p2\n```\n\n```{r}\np \u003c- ggplot(mpg, aes(class, displ)) +\n  geom_boxplot() +\n  facet_grid(cols = vars(cyl), scales = \"free\") +\n  theme_test() + \n  theme(plot.title = element_text(size = 20),\n        axis.text.x = element_text(angle = 45, hjust = 1))\n\np3 \u003c- p + stat_compare() + ggtitle(\"ggcompare::stat_compare\")\n\n# missing test information in all panels\np4 \u003c- p + ggpubr::stat_compare_means() + ggtitle(\"ggpubr::stat_compare_means\")\n```\n\n```{r echo=FALSE, fig.height=12, fig.width=15}\np3 / p4\n```\n\n- P-value correction\n\n```{r}\n# Layer-level\np5 \u003c- p + stat_compare(ref_group = 1, correction = \"fdr\") + ggtitle(\"Layer-level P-value adjustment\")\n# Panel-level\np6 \u003c- p + stat_compare(ref_group = 1, correction = \"fdr\", panel_indep = TRUE) + ggtitle(\"Panel-level P-value adjustment\")\n```\n\n```{r echo=FALSE, fig.height=12, fig.width=15}\np5 / p6\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/hmu-wh.github.io%2Fggcompare%2F","html_url":"https://awesome.ecosyste.ms/projects/hmu-wh.github.io%2Fggcompare%2F","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/hmu-wh.github.io%2Fggcompare%2F/lists"}