{"id":13858256,"url":"https://github.com/s6juncheng/ggpval","last_synced_at":"2025-07-29T23:32:38.019Z","repository":{"id":44496989,"uuid":"93850053","full_name":"s6juncheng/ggpval","owner":"s6juncheng","description":"Add statistical test or annotation to your ggplot2 plots, ","archived":false,"fork":false,"pushed_at":"2022-07-11T16:47:21.000Z","size":8201,"stargazers_count":46,"open_issues_count":8,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-22T03:51:22.146Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://s6juncheng.github.io/ggpval/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/s6juncheng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-09T10:57:10.000Z","updated_at":"2024-12-31T22:11:09.000Z","dependencies_parsed_at":"2022-09-06T07:02:23.961Z","dependency_job_id":null,"html_url":"https://github.com/s6juncheng/ggpval","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/s6juncheng/ggpval","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s6juncheng%2Fggpval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s6juncheng%2Fggpval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s6juncheng%2Fggpval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s6juncheng%2Fggpval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s6juncheng","download_url":"https://codeload.github.com/s6juncheng/ggpval/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s6juncheng%2Fggpval/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267409279,"owners_count":24082604,"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-07-27T02:00:11.917Z","response_time":82,"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":"2024-08-05T03:02:01.991Z","updated_at":"2025-07-29T23:32:37.995Z","avatar_url":"https://github.com/s6juncheng.png","language":"R","funding_links":[],"categories":["R","Data and models"],"sub_categories":[],"readme":"\u003c!-- badges: start --\u003e \n[![CRAN checks](https://cranchecks.info/badges/summary/ggpval)](https://cran.r-project.org/web/checks/check_results_ggpval.html)\n[![](http://cranlogs.r-pkg.org/badges/last-month/ggpval?color=green)](https://cran.r-project.org/package=ggpval)\n[![](https://www.r-pkg.org/badges/version/ggpval?color=green)](https://cran.r-project.org/package=ggpval)\n[![Dependencies](https://tinyverse.netlify.com/badge/ggpval)](https://cran.r-project.org/package=ggpval)\n\u003c!-- badges: end --\u003e\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\nggpval\n======\n\n`ggpval` allows you to perform statistic tests and add the corresponding\np-values to ggplots automatically. P-values can be presented numerically\nor as stars (e.g. \\*, \\*\\*). Alternatively, one can also make any text\nannotation between groups.\n\nInstallation\n------------\n\n``` r\n# Install `ggpval` from CRAN:\ninstall.packages(\"ggpval\")\n\n# You can install the lastest ggpval from github with:\n# install.packages(\"devtools\")\ndevtools::install_github(\"s6juncheng/ggpval\")\n```\n\nExample\n-------\n\nSimulate data with groups.\n\n``` r\nlibrary(ggpval)\nlibrary(data.table)\nlibrary(ggplot2)\nA \u003c- rnorm(200, 0, 3)\nB \u003c- rnorm(200, 2, 4)\nG \u003c- rep(c(\"G1\", \"G2\"), each = 100)\ndt \u003c- data.table(A, B, G)\ndt \u003c- melt(dt, id.vars = \"G\")\ntheme_set(theme_classic())\n```\n\nA trivial boxplot example\n-------------------------\n\nGive the group pairs you want to compare in `pairs`. By default we use `wilcox.test`, you can al well use `t.test` and others. The key word arguments for the test function, such as `alternative = c(\"two.sided\", \"less\", \"greater\")`, `paired=` can be directly given. By default, we use the save default arguments as the test function.\n\n``` r\nplt \u003c- ggplot(dt, aes(variable, value)) +\n  geom_boxplot() +\n  geom_jitter()\n\nadd_pval(plt, pairs = list(c(1, 2)), test='wilcox.test', alternative='two.sided')\n```\n\n\u003cimg src=\"man/figures/unnamed-chunk-3-1.png\" alt=\"\" width=\"450\"/\u003e\n\n\nConvert with plotly with `ggplotly`\n-------------------\n\nTo convert the plot with `ggpval` annotation to plotly, add `plotly=TRUE`:\n\n```r\nplt \u003c- ggplot(dt, aes(variable, value)) +\n  geom_boxplot() +\n  geom_jitter()\nplt \u003c- add_pval(plt, pairs = list(c(1, 2)), test = \"t.test\", plotly=TRUE)\nplotly::ggplotly(plt) \n```\n\n\u003cimg src=\"man/figures/plotly.png\" alt=\"\" width=\"450\"/\u003e\n\n\nBoxplot with facets\n-------------------\n\n``` r\nplt \u003c- ggplot(dt, aes(variable, value)) +\n  geom_boxplot() +\n  geom_jitter() +\n  facet_wrap(~G)\nadd_pval(plt, pairs = list(c(1, 2)))\n```\n\n\u003cimg src=\"man/figures/unnamed-chunk-4-1.png\" alt=\"\" width=\"650\"/\u003e\n\n\nBar plot\n--------\n\n`ggpval` tries to infer the column which contains the data to do\nstatistical testing. In case this inference was wrong or not possible\n(for instance the raw data column was not mapped in ggplot object), you\ncan specify the correct column name with `response=`.\n\n``` r\ndt[, mu := mean(value),\n   by = c(\"G\", \"variable\")]\n\ndt[, se := sd(value) / .N,\n   by = c(\"G\", \"variable\")]\n\nplt_bar \u003c- ggplot(dt, aes(x=variable, y=mu, fill = variable)) +\n  geom_bar(stat = \"identity\", position = 'dodge') +\n  geom_errorbar(aes(ymin=mu-se, ymax=mu+se),\n                width = .2) +\n  facet_wrap(~G)\n\nadd_pval(plt_bar, pairs = list(c(1, 2)), response = 'value')\n```\n\n\u003cimg src=\"man/figures/unnamed-chunk-5-1.png\" alt=\"\" width=\"650\"/\u003e\n\n\nAdditional arguments for statistical function can also be directly\nspecified. Here we also the conventional \"\\*\" format for significance\nlevel.\n\n``` r\nadd_pval(plt_bar, pairs = list(c(1, 2)), \n         test = 't.test',\n          alternative = \"less\",\n         response = 'value',\n         pval_star = T)\n```\n\n\u003cimg src=\"man/figures/unnamed-chunk-6-1.png\" alt=\"\" width=\"650\"/\u003e\n\nAnnotate your plot with text\n------------------\n\n``` r\nadd_pval(plt, pairs = list(c(1, 2)), annotation = \"Awesome\")\n```\n\n\u003cimg src=\"man/figures/unnamed-chunk-7-1.png\" alt=\"\" width=\"650\"/\u003e\n\nIn case you to want give different annotations to each facets, provide\nyour annotation as a list\n\n``` r\nadd_pval(plt, pairs = list(c(1, 2)), annotation = list(\"Awesome1\", \"Awesome2\"))\n```\n\n\u003cimg src=\"man/figures/unnamed-chunk-8-1.png\" alt=\"\" width=\"650\"/\u003e\n\nBugs and issues\n---------------\n\nPlease report bugs and issues on github issue page:\n\u003ca href=\"https://github.com/s6juncheng/ggpval/issues\" class=\"uri\"\u003ehttps://github.com/s6juncheng/ggpval/issues\u003c/a\u003e.\nContributions are welcome.\n\nAcknowledgement\n---------------\n\nThanks to Vicente Yépez for testing and helping with improvement of the\npackage.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs6juncheng%2Fggpval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs6juncheng%2Fggpval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs6juncheng%2Fggpval/lists"}