{"id":13711182,"url":"https://github.com/kbelisar/ggcorset","last_synced_at":"2025-10-22T03:17:49.839Z","repository":{"id":40995407,"uuid":"363011191","full_name":"kbelisar/ggcorset","owner":"kbelisar","description":"The 'ggcorset' package - Introducing corset plots!","archived":false,"fork":false,"pushed_at":"2024-09-06T00:09:06.000Z","size":25465,"stargazers_count":34,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T06:01:55.302Z","etag":null,"topics":["corset-plot","cran-r","data-visualization","data-viz","ggplot2","rstats","rstats-package","visualization"],"latest_commit_sha":null,"homepage":"https://CRAN.R-project.org/package=ggcorset","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/kbelisar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-04-30T03:04:31.000Z","updated_at":"2024-10-10T19:14:59.000Z","dependencies_parsed_at":"2024-04-06T04:22:12.948Z","dependency_job_id":"68747354-add6-44b4-ab0b-3dc6d03cfc8b","html_url":"https://github.com/kbelisar/ggcorset","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbelisar%2Fggcorset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbelisar%2Fggcorset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbelisar%2Fggcorset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbelisar%2Fggcorset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kbelisar","download_url":"https://codeload.github.com/kbelisar/ggcorset/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252607033,"owners_count":21775415,"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":["corset-plot","cran-r","data-visualization","data-viz","ggplot2","rstats","rstats-package","visualization"],"created_at":"2024-08-02T23:01:05.463Z","updated_at":"2025-10-22T03:17:44.800Z","avatar_url":"https://github.com/kbelisar.png","language":"R","funding_links":[],"categories":["Plot layers"],"sub_categories":[],"readme":"![CRAN](https://www.r-pkg.org/badges/version/ggcorset)\n[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/grand-total/ggcorset?color=yellow)](https://r-pkg.org/pkg/ggcorset)\n![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/ggcorset?color=lightgrey)\n[![R-CMD-check](https://github.com/kbelisar/ggcorset/actions/workflows/r_cmd_check.yml/badge.svg)](https://github.com/kbelisar/ggcorset/actions/workflows/r_cmd_check.yml)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4905031.svg)](https://doi.org/10.5281/zenodo.4905031)\n\n# The 'ggcorset' package\n\n\u003cimg align=\"right\" width=\"475\" height=\"325\" src=\"https://github.com/kbelisar/ggcorset/blob/main/visualizations/example_corset_plot_github_eyelets.png\"\u003e\n\nThe 'ggcorset' package introduces a visualization technique coined the corset plot. It is used strictly to visualize repeat measures data at 2 time points (such as pre- and post- data). The distribution of measurements at each time point is visualized using a half violin, whilst the trajectories of individual change are visualized via spaghetti plots by connecting these two points linearly. These lines can be filled to visualize the magnitude of change or other user-defined observed value. This method of visualization is ideal for showing the true heterogeneity of data, including differences by sub-groups.\n\nThe package relies on the '[ggplot2](https://ggplot2.tidyverse.org)' package to produce the visualizations. As such, the corset plot allows for easy integration with 'ggplot2', so that users can customize their visualizations as required. This package is geared towards users with limited experience in R, creating corset plots using data in either wide or long format using the functions `gg_corset()` or `gg_corset_elongated()`, respectively.\n\nThe 'ggcorset' package allows for easy customization by offering different descriptive features by group. Specifically, 'eyelets' can be used to show either standard error means (SEM) or the mean +/- 1 standard deviation by group, and 'faceted' corsets can be used highlight the distributions of each group.\n\n\u003cp align=\"center\"\u003e\n\u003cimg width=\"700\" height=\"450\" src=\"https://github.com/kbelisar/ggcorset/blob/main/visualizations/example_corset_plot_github_faceted.png\"\u003e\n\u003c/p\u003e\n\n\n## Installation\n\nInstall the package directly from CRAN using:\n\n```\ninstall.packages(\"ggcorset\")\n```\n\nThe latest version of this package can also be installed using install_github() from the 'devtools' package to download from this GitHub respository directly:\n\n```\ndevtools::install_github(\"kbelisar/ggcorset\")\n```\n\n## Corset Plots in Action\n\nExamples of corset plots in use, can be seen in the following publications: \n\n\u003e Minhas, M., Belisario, K., González-Roz, A., Halladay, J., Murphy, J.G. and MacKillop, J. (2021), COVID-19 impacts on drinking and mental health in emerging adults: Longitudinal changes and moderation by economic disruption and sex. Alcohol Clin Exp Res, https://doi.org/10.1111/acer.14624\n\n\u003e González-Roz, A., Haik, A. K., Rahman, L., Todi, A. A., Kane, C., Walji, A., Dickerman S. R., Scarfe, M., Levitt E. E., Belisario, K., Kelly, J. F., \u0026 MacKillop, J. (2022) Impacts of the COVID-19 public health restrictions on substance use, mental health, and psychosocial functioning among individuals with alcohol use disorder, The American Journal of Drug and Alcohol Abuse, 48:6, 712-723, https://doi.org/10.1080/00952990.2022.2134021\n\n\u003e You, Y., Liu, J., Yao, Z., Zhang, S., Chen, K., \u0026 Ma, X. (2023). Neural mechanisms of long-term exercise intervention on cognitive performance among short-sleep young adults: a hemodynamic study. Sleep Medicine, 110, 7-16, https://doi.org/10.1016/j.sleep.2023.07.020\n\n\u003e Griffiths, K.R., Boulet, S., Barakat, S. et al. Exploring bi-directional impacts of Lisdexamfetamine dimesylate on psychological comorbidities and quality of life in people with Binge Eating Disorder. J Eat Disord 12, 80 (2024). https://doi.org/10.1186/s40337-024-01041-9\n\n\n## The ggcorset functions\n\n### gg_corset()\n\nThis function is used to create a corset plot with data in the wide format. It takes the following arguments:\n\n`data` = the name of the data frame\n\n`y_var1` = the name of the measured variable at the first time point\n\n`y_var2` = the name of the measured variable at the second time point\n\n`group` = the name of the units measured at each time point (such as id)\n\n`c_var` = the name of the variable to visualize by line colour\n\n`eyelets` = optional argument (defaults to FALSE) which creates either standard error means for the c_var (default) or 1 standard deviation above/ below the mean as defined by the 'e_type` argument\n\n`e_type` = optional argument when `eyelets` is set to TRUE. One of \"SE\" (default) or \"SD\"\n\n`faceted` = optional argument (defaults to FALSE) which facets corset plots by c_var\n\n`facet_design` = defaults to \"original\" when `faceted` is set to TRUE. One of \"original\", \"line\", or \"group\"\n\n`vio_fill` = optional argument to change the fill colour of the half violins (defaults to a soft black)\n\n`line_size` = optional argument to change the size (thickness) of the lines (default is 0.25)\n\n`line_col` = optional argument when `facet_design` is set to \"line\" to change the colour of the background group lines\n\n`line_dodge` = optional argument to change the amount of vertical dodge of the lines (default is 0.1)\n\n### gg_corset_elongated()\n\nThis function is used to create a corset plot with data in the long format. It takes the following arguments:\n\n`data` = the name of the data frame\n\n`x_var` = the name of the x-axis variable (time variable)\n\n`x_vals` = the values representing the two time points (in chronological order)\n\n`y_var` = the name of the repeated measure\n\n`group` = the name of the units measured at each time point (such as id)\n\n`c_var` = the name of the variable to visualize by line colour\n\n`eyelets` = optional argument (defaults to FALSE) which creates standard error means for the c_var (default) or 1 standard deviation above/ below the mean as defined by the 'e_type` argument\n\n`e_type` = optional argument when `eyelets` is set to TRUE. One of \"SE\" (default) or \"SD\"\n\n`faceted` = optional argument (defaults to FALSE) which facets corset plots by c_var with soft grey lines denoting entire sample trajectories\n\n`facet_design` = defaults to \"original\" when `faceted` is set to TRUE. One of \"original\", \"line\", or \"group\"\n\n`vio_fill` = optional argument to change the fill colour of the half violins (defaults to a soft black)\n\n`line_size` = optional argument to change the size (thickness) of the lines (default is 0.25)\n\n`line_col` = optional argument when `facet_design` is set to \"line\" to change the colour of the background group lines\n\n`line_dodge` = optional argument to change the amount of vertical dodge of the lines (default is 0.1)\n\n### theme_ggcorset()\n\nThis is a 'ggplot2' theme to quickly polish visualizations, and can be added to any ggplot2 object.\n\n\n## A Quick Guide on 'ggplot2' Customization:\n\nBy creating a corset plot as an R object, 'ggplot2' customizations can easily be made. Here are a few changes to get started:\n\n`xlab()` - Change the x-axis title\n\n`ylab()` - Change the y-axis title\n\n`ggtitle()` - Title of the plot\n\n`scale_x_discrete()` - Change the labels of time1 and time2 (particularly helpful when using the `gg_corset()` function)\n\n`scale_colour_manual()` - Custom colours as specified by the user (via `values =` argument)\n\n`scale_colour_gradientn()` - Custom gradient of colours for continuous outcomes\n\n`scale_colour_viridis()` - Custom colour-blind friendly colours for the c_var variable using the 'viridis' package\n\n`guides(colour = guide_legend(override.aes = list(linewidth = 3)))` - Overrides thickness of legend so colours are more easily seen\n\n\n## Full Example\n\nThe example data set included in this package (named 'drinkdays') is in wide format, and has been simulated with mock data. This data set consists of 300 individuals, with 1 individual per row, as identified by a distinct 'id'. The repreated measure is the number of drinking days per week, measured at 'time1' and 'time2'.\n\nThe variable 'change', is calculated by subtracting 'time1' from 'time2', and is used for the `c_var` argument:\n\n```\nlibrary(ggcorset)\n\ndata(\"drinkdays\")\n\n#Calculating Change\ndrinkdays$change \u003c- drinkdays$time2-drinkdays$time1\n\n```\n\n**Since this data is in wide format**, the function `gg_corset()` will be used to create the corset plot using the following code:\n\n```\nplot \u003c- gg_corset(drinkdays, y_var1 = \"time1\", y_var2 = \"time2\", \n                  group = \"id\", c_var = \"change\", eyelets = F) +\n        theme_ggcorset()                                           # A ggcorset theme for polished corset plots!\n\nplot # see the initial visualization\n```\n\n**Changes to the corset plot can be made by using 'ggplot2':**\n```\nlibrary(ggplot2)\n\nplot + \n  scale_colour_gradientn(\"Direction of Change\",\n                         colours = MetBrewer::met.brewer(\"Troy\")) +     # Changes legend title, and selects a colour-palette\n  ggtitle(\"Change in Drinking Days\") +                                  # Changes the plot title\n  ylab(\"Number of Drinking Days per Week\") +                            # Changes the y-axis title\n  xlab(\"\") +                                                            # Changes the x-axis title (removes in favour of the 2 time point labels below)\n  scale_x_discrete(labels = c(\"Pre\",\"Post\")) +                          # Changes the labels of the 2 time points (on the x-axis)\n  guides(colour = guide_legend(override.aes = list(linewidth = 3)))     # Makes the legend lines thicker\n\n```\n**Example Corset Plot:**\n\nThis plot was solely created using the example data set and the code used in the example above:\n\n\u003cp align=\"center\"\u003e\n\u003cimg width=\"700\" height=\"450\" src=\"https://github.com/kbelisar/ggcorset/blob/main/visualizations/example_corset_plot_github_continuous.png\"\u003e\n\u003c/p\u003e\n\nAdditional corset plot examples and uses can be found in detail in the CRAN [vignette](https://cran.r-project.org/web/packages/ggcorset/vignettes/corset_plot_intro.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkbelisar%2Fggcorset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkbelisar%2Fggcorset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkbelisar%2Fggcorset/lists"}