{"id":14067376,"url":"https://github.com/caijun/ggcorrplot2","last_synced_at":"2025-03-17T09:30:52.995Z","repository":{"id":40454907,"uuid":"227357653","full_name":"caijun/ggcorrplot2","owner":"caijun","description":"Implementation of corrplot using ggplot2","archived":false,"fork":false,"pushed_at":"2022-05-07T11:16:36.000Z","size":19843,"stargazers_count":38,"open_issues_count":8,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-16T10:41:19.682Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caijun.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-11T12:11:18.000Z","updated_at":"2025-02-28T07:40:15.000Z","dependencies_parsed_at":"2022-07-12T18:02:22.607Z","dependency_job_id":null,"html_url":"https://github.com/caijun/ggcorrplot2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caijun%2Fggcorrplot2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caijun%2Fggcorrplot2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caijun%2Fggcorrplot2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caijun%2Fggcorrplot2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caijun","download_url":"https://codeload.github.com/caijun/ggcorrplot2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244008968,"owners_count":20382940,"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":[],"created_at":"2024-08-13T07:05:33.815Z","updated_at":"2025-03-17T09:30:51.815Z","avatar_url":"https://github.com/caijun.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n# ggcorrplot2\n\n[![Build Status](https://travis-ci.org/caijun/ggcorrplot2.svg?branch=master)](https://travis-ci.org/caijun/ggcorrplot2)\n\nImplementation of corrplot using ggplot2\n\n## Introduction\n\nReinventing wheels is not what I like doing. [corrplot](https://CRAN.R-project.org/package=corrplot) is a great R package, but I am really tired of customizing the appearance of corrplot, for example, the space between colorbar and its tick labels, the space around the plot that I don't know how to control when writing it to PDF on my macOS. This is most likely because I am more familiar with the Grammar of Graphics implemented in ggplot2 than the base plotting system in R. There are several R packages (e.g., [ggcorrplot](https://github.com/kassambara/ggcorrplot) developed by Alboukadel Kassambara, [ggcorr](https://github.com/briatte/ggcorr) developed by François Briatte) that can visualize a correlation matrix into a [corrgram](https://www.tandfonline.com/doi/abs/10.1198/000313002533) using ggplot2; however, they are unable to visualize a correlation matrix using ellipse and mixed methods. **ggcorrplot2** has implemented only a subset of features of **corrplot** to meet my urgent needs. See examples in the **Getting started** section. More functionality will be added in the future as needed.\n\n## Installation\n\nGet the development version from github:\n\n```r\nif (!requireNamespace(\"devtools\")) install.packages(\"devtools\")\ndevtools::install_github(\"caijun/ggcorrplot2\")\n```\n\n## Getting started\n\nThe `mtcars` dataset will be used to demonstrate the usages of **ggcorrplot2**. Most parameters of **ggcorrplot2** functions are the same as those of **corrplot**. Therefore, it's easy for users to migrate from **corrplot** to **ggcorrplot2**.\n\n```{r, echo = FALSE}\nknitr::opts_chunk$set(\n  dpi = 200,\n  fig.path = \"figs/README-\"\n)\n```\n\n```{r, fig.height=4}\nlibrary(ggcorrplot2)\n\ndata(mtcars)\n# Use corr.test() from psych package to calculate the correlation matrix and \n# corresponding p value matrix without adjustment.\nlibrary(psych)\nct \u003c- corr.test(mtcars, adjust = \"none\")\ncorr \u003c- ct$r\np.mat \u003c- ct$p\n\n# Visualize the correlation matrix\n# --------------------------------\n# method = \"circle\" (default)\nggcorrplot(corr)\n\n# method = \"square\"\nggcorrplot(corr, method = \"square\")\n\n# method = \"ellipse\"\nggcorrplot(corr, method = \"ellipse\")\n\n# method = \"number\", display the correlation coefficients\nggcorrplot(corr, method = \"number\")\n\n# Visualize the upper or lower triangle of correlation matrix\n# -----------------------------------------------------------\n# the upper triangle\nggcorrplot(corr, type = \"upper\")\n\n# the lower triangle\nggcorrplot(corr, type = \"lower\")\n\n# Visualize the correlation matrix using mixed methods\n# ----------------------------------------------------\n# default: upper = \"circle\", lower = \"number\"\nggcorrplot.mixed(corr)\n\n# upper = \"ellipse\", lower = \"number\"\nggcorrplot.mixed(corr, upper = \"ellipse\", lower = \"number\")\n\n# Combine correlogram with the significance test\n# ----------------------------------------------\n# Insignificant coefficients according to the default significant level \n# (sig.lvl = 0.05) are indicated by X by default.\nggcorrplot.mixed(corr, upper = \"ellipse\", lower = \"number\", p.mat = p.mat)\n\n# Leave blank on insignificant coefficients\nggcorrplot.mixed(corr, upper = \"ellipse\", lower = \"number\", p.mat = p.mat, \n                 insig = \"blank\")\n\n# Label significant coefficients with asterisks (*, default) denoting the significance level\nggcorrplot.mixed(corr, upper = \"ellipse\", lower = \"number\", p.mat = p.mat, \n                 insig = \"label_sig\", sig.lvl = c(0.05, 0.01, 0.001))\n\n# Label significant coefficients with varying number of + denoting the significance level\n(p \u003c- ggcorrplot.mixed(corr, upper = \"ellipse\", lower = \"number\", p.mat = p.mat, \n                 insig = \"label_sig\", sig.lvl = c(0.05, 0.01, 0.001), pch = \"+\", \n                 pch.cex = 4))\n```\n\nThe above examples reproduce some features of **corrplot**. In the following example, the added advantages of implementing **corrplot** using ggplot2, such as customizing the appearance of corrgram, combining a corrgram with other plots (including non-corrgrams) into one plot using [cowplot](https://github.com/wilkelab/cowplot), are demonstrated.\n\n```{r, fig.width=9, fig.height=5, fig.align=\"center\", message=FALSE}\n# Customize the appearance of corrplot using functions from ggplot2\nlibrary(ggplot2)\n# Use different color palette\ncol1 \u003c- colorRampPalette(c(\"#7F0000\", \"red\", \"#FF7F00\", \"yellow\", \"white\",\n                           \"cyan\", \"#007FFF\", \"blue\", \"#00007F\"))\n# Change the colorbar direction to horizontal and place it at the bottom\n# As mixed methods are used, there are two scales: color filled in ellipse and \n# number color\np \u003c- p + scale_fill_gradientn(colours = col1(10), limits = c(-1, 1),\n                                guide = guide_colorbar(\n                                  direction = \"horizontal\",\n                                  title = \"\",\n                                  nbin = 1000,\n                                  ticks.colour = \"black\",\n                                  frame.colour = \"black\",\n                                  barwidth = 15,\n                                  barheight = 1.5)) +\n  scale_colour_gradientn(colours = col1(10), limits = c(-1, 1),\n                       guide = guide_colorbar(\n                         direction = \"horizontal\",\n                         title = \"\",\n                         nbin = 1000,\n                         ticks.colour = \"black\",\n                         frame.colour = \"black\",\n                         barwidth = 15,\n                         barheight = 1.5)) +\n  theme(legend.position = \"bottom\")\np\n\n# Combine a lower corrgram and a mixed corrgram side by side with a shared colorbar on the bottom\n\n# NAs are allowed in correlation matrix and p value matrix, which are labelled as NA\n# Assign NAs\nrid \u003c- c(2, 3, 1, 2)\ncid \u003c- c(3, 2, 2, 1)\npos \u003c- cbind(rid, cid)\ncorr[pos] \u003c- NA\np.mat[pos] \u003c- NA\n\n# a lower corrgram\np1 \u003c- ggcorrplot(corr, type = \"lower\", method = \"square\", p.mat = p.mat, \n                 insig = \"label_sig\", sig.lvl = c(0.05, 0.01, 0.001), show.diag = FALSE)\n# a mixed corrgram\np2 \u003c- ggcorrplot.mixed(corr, upper = \"ellipse\", lower = \"number\", p.mat = p.mat, \n                       insig = \"label_sig\", sig.lvl = c(0.05, 0.01, 0.001), \n                       pch = \"+\", pch.cex = 4)\n\nlibrary(cowplot)\nprow \u003c- plot_grid(p1 + theme(legend.position = \"none\"),\n                  p2 + theme(legend.position = \"none\"),\n                  rel_widths = c(1, 1), nrow = 1, align = 'hv',\n                  labels = c(\"(a)\", \"(b)\"), label_x = 0, label_y = 1)\n\n# Extract the legend from the first corrgram\nlegend \u003c- get_legend(p1)\n# Add the legend to the bottom of the plot row we made earlier.\np \u003c- cowplot::plot_grid(prow, legend, ncol = 1, rel_heights  = c(1, 0.15))\np\n```\n\n## Citation\n\nTo cite the 'ggcorrplot2' package in publications use:\n```\n  Jun Cai, Granville Matheson and Samson Leonard Daniël (2022). ggcorrplot2: Visualize a Correlation Matrix using ggplot2. R package version 0.1.2.\n```\n\nA BibTeX entry for LaTeX users is\n```\n  @Manual{,\n    title = {ggcorrplot2: Visualize a Correlation Matrix using ggplot2},\n    author = {Jun Cai and Granville Matheson and Samson Leonard Daniël},\n    year = {2022},\n    note = {R package version 0.1.2},\n    url = {https://github.com/caijun/ggcorrplot2},\n  }\n```\n\nThe above citation information can be generated by calling `citation(\"ggcorrplot2\")` in R.\n\n## Contact\n\nBugs and feature requests can be filed to\n\u003chttps://github.com/caijun/ggcorrplot2/issues\u003e. Pull requests are also welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaijun%2Fggcorrplot2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaijun%2Fggcorrplot2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaijun%2Fggcorrplot2/lists"}