{"id":13711162,"url":"https://tgerke.github.io/ggconsort/","last_synced_at":"2025-05-06T20:32:01.761Z","repository":{"id":76833020,"uuid":"395106164","full_name":"tgerke/ggconsort","owner":"tgerke","description":"An R package for creating CONSORT diagrams with ggplot","archived":false,"fork":false,"pushed_at":"2022-10-26T13:20:36.000Z","size":1615,"stargazers_count":50,"open_issues_count":9,"forks_count":8,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-11-09T19:12:07.292Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://tgerke.github.io/ggconsort","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/tgerke.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-08-11T20:15:04.000Z","updated_at":"2024-07-29T10:11:12.000Z","dependencies_parsed_at":"2024-01-17T16:08:27.624Z","dependency_job_id":"3c0d5079-9e40-4150-bfce-0454e4523eb2","html_url":"https://github.com/tgerke/ggconsort","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/tgerke%2Fggconsort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tgerke%2Fggconsort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tgerke%2Fggconsort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tgerke%2Fggconsort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tgerke","download_url":"https://codeload.github.com/tgerke/ggconsort/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224528341,"owners_count":17326348,"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-02T23:01:05.209Z","updated_at":"2024-11-13T21:31:32.868Z","avatar_url":"https://github.com/tgerke.png","language":"R","funding_links":[],"categories":["Plot layers"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\",\n  fig.retina = 3\n)\n```\n\n# ggconsort \u003cimg src=\"man/figures/logo.png\" align=\"right\" height=\"139\" /\u003e\n\n\u003c!-- badges: start --\u003e\n\u003c!-- badges: end --\u003e\n\n## Overview\n\nThe goal of ggconsort is to provide convenience functions for creating [CONSORT diagrams](http://www.consort-statement.org/consort-statement/flow-diagram) with ggplot2. ggconsort segments CONSORT creation into two stages: (1) counting and annotation at the time of data wrangling, and (2) diagram layout and aesthetic design. With the introduction of a `ggconsort_cohort` class, stage (1) can be accomplished within dplyr chains. Specifically, the following functions are implemented inside a dplyr chain to define a `ggconsort_cohort`:\n\n* `cohort_start()` initializes a `ggconsort_cohort` object which contains a labeled copy of the source data\n* `cohort_define()` constructs cohorts that are variations of the source data or other cohorts\n* `cohort_label()` adds labels to each named cohort within the `ggconsort_cohort` object\n\nStage 2 makes use of three ggconsort `consort_` verbs which equip the `ggconsort_cohort` object with `ggconsort` properties. The `ggconsort` object can be viewed with ggplot via `geom_consort() + theme_consort()`. `plot` and `print` methods are also available for the `ggconsort` object for visually iterative development.\n\n* `consort_box_add()` adds a text box to the CONSORT diagram\n* `consort_arrow_add()` adds an arrow to the CONSORT diagram\n* `consort_line_add()` adds a line (without an arrow head) the CONSORT diagram\n\n## Installation\n\nYou can install the released version of ggconsort from [GitHub](https://github.com/tgerke/ggconsort) with:\n\n``` r\n# install.packages(\"devtools\")\ndevtools::install_github(\"tgerke/ggconsort\")\n```\n\n## Usage\n\nTo demonstrate usage, we use a simulated dataset within ggconsort called `trial_data`, which contains 1200 patients who were approached to participate in a randomized trial comparing Drug A to Drug B. \n\n```{r trial_data}\nlibrary(ggconsort)\n\nhead(trial_data)\n```\n\nOf the 1200 approached patients, only a subset were ultimately randomized: some declined to participate or were ineligible (due to prior chemotherapy or bone metastasis). We will use ggconsort verbs and geoms to count the patient flow and represent the process in a CONSORT diagram.\n\nWe first define the `ggconsort_cohort` object (`study_cohorts`) in the following dplyr chain.\n\n```{r example-cohort, message=FALSE}\nlibrary(dplyr)\n\nstudy_cohorts \u003c- \n  trial_data %\u003e%\n  cohort_start(\"Assessed for eligibility\") %\u003e%\n  # Define cohorts using named expressions --------------------\n  # Notice that you can use previously defined cohorts in subsequent steps\n  cohort_define(\n    consented = .full %\u003e% filter(declined != 1),\n    consented_chemonaive = consented %\u003e% filter(prior_chemo != 1),\n    randomized = consented_chemonaive %\u003e% filter(bone_mets != 1),\n    treatment_a = randomized %\u003e% filter(treatment == \"Drug A\"),\n    treatment_b = randomized %\u003e% filter(treatment == \"Drug B\"),\n    # anti_join is useful for counting exclusions -------------\n    excluded = anti_join(.full, randomized, by = \"id\"),\n    excluded_declined = anti_join(.full, consented, by = \"id\"),\n    excluded_chemo = anti_join(consented, consented_chemonaive, by = \"id\"),\n    excluded_mets = anti_join(consented_chemonaive, randomized, by = \"id\")\n  ) %\u003e%\n  # Provide text labels for cohorts ---------------------------\n  cohort_label(\n    consented = \"Consented\",\n    consented_chemonaive = \"Chemotherapy naive\",\n    randomized = \"Randomized\",\n    treatment_a = \"Allocated to arm A\",\n    treatment_b = \"Allocated to arm B\",\n    excluded = \"Excluded\",\n    excluded_declined = \"Declined to participate\",\n    excluded_chemo = \"Prior chemotherapy\",\n    excluded_mets = \"Bone metastasis\"\n  )\n```\n\nWe can have a look at the `study_cohorts` object with its print and summary methods:\n\n```{r print-summary}\nstudy_cohorts\n\nsummary(study_cohorts)\n```\n\nNext, we add CONSORT \"boxes\" and \"arrows\" with appropriate ggconsort verbs, and plot with the CONSORT diagram `ggplot`. Note the use of `cohort_count_adorn()`, which is a convenience function that glues cohort counts to their labels.\n\n```{r example-consort}\nlibrary(ggplot2)\n\nstudy_consort \u003c- study_cohorts %\u003e%\n  consort_box_add(\n    \"full\", 0, 50, cohort_count_adorn(study_cohorts, .full)\n  ) %\u003e%\n  consort_box_add(\n    \"exclusions\", 20, 40, glue::glue(\n      '{cohort_count_adorn(study_cohorts, excluded)}\u003cbr\u003e\n      • {cohort_count_adorn(study_cohorts, excluded_declined)}\u003cbr\u003e\n      • {cohort_count_adorn(study_cohorts, excluded_chemo)}\u003cbr\u003e\n      • {cohort_count_adorn(study_cohorts, excluded_mets)}\n      ')\n  ) %\u003e%\n  consort_box_add(\n    \"randomized\", 0, 30, cohort_count_adorn(study_cohorts, randomized)\n  ) %\u003e%\n  consort_box_add(\n    \"arm_a\", -30, 10, cohort_count_adorn(study_cohorts, treatment_a)\n  ) %\u003e%\n  consort_box_add(\n    \"arm_b\", 30, 10, cohort_count_adorn(study_cohorts, treatment_b)\n  ) %\u003e%\n  consort_arrow_add(\n    end = \"exclusions\", end_side = \"left\", start_x = 0, start_y = 40\n  ) %\u003e%\n  consort_arrow_add(\n    \"full\", \"bottom\", \"randomized\", \"top\"\n  ) %\u003e% \n  consort_arrow_add(\n    start_x = 0, start_y = 30, end_x = 0, end_y = 20,\n  ) %\u003e%\n  consort_line_add(\n    start_x = -30, start_y = 20, end_x = 30, end_y = 20,\n  ) %\u003e% \n  consort_arrow_add(\n    end = \"arm_a\", end_side = \"top\", start_x = -30, start_y = 20\n  ) %\u003e%\n  consort_arrow_add(\n    end = \"arm_b\", end_side = \"top\", start_x = 30, start_y = 20\n  )\n\nstudy_consort %\u003e%\n  ggplot() + \n  geom_consort() +\n  theme_consort(margin_h = 8, margin_v = 1) +\n  # you can include other ggplot geoms, as needed -------------\n  ggtext::geom_richtext(\n    aes(x = 0, y = 10, label = \"Allocation\"),\n    fill = \"#9bc0fc\"\n  )\n```\n\nAt this point, we are ready for analysis. The following retrieves the desired data frame of randomized subjects:\n\n```{r pull-data}\nstudy_cohorts %\u003e%\n  cohort_pull(randomized)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/tgerke.github.io%2Fggconsort%2F","html_url":"https://awesome.ecosyste.ms/projects/tgerke.github.io%2Fggconsort%2F","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/tgerke.github.io%2Fggconsort%2F/lists"}