{"id":16571728,"url":"https://github.com/coolbutuseless/facetious","last_synced_at":"2025-03-21T12:31:01.164Z","repository":{"id":95359524,"uuid":"387744916","full_name":"coolbutuseless/facetious","owner":"coolbutuseless","description":"Home to some alternate facetting for ggplot2","archived":false,"fork":false,"pushed_at":"2021-07-21T11:27:23.000Z","size":646,"stargazers_count":36,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-01T06:11:15.187Z","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/coolbutuseless.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-07-20T09:46:35.000Z","updated_at":"2024-07-17T11:42:02.000Z","dependencies_parsed_at":"2023-07-04T20:17:35.478Z","dependency_job_id":null,"html_url":"https://github.com/coolbutuseless/facetious","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/coolbutuseless%2Ffacetious","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolbutuseless%2Ffacetious/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolbutuseless%2Ffacetious/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolbutuseless%2Ffacetious/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coolbutuseless","download_url":"https://codeload.github.com/coolbutuseless/facetious/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244135909,"owners_count":20403798,"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-10-11T21:25:02.848Z","updated_at":"2025-03-21T12:31:00.442Z","avatar_url":"https://github.com/coolbutuseless.png","language":"R","funding_links":[],"categories":["Presentation, composition and scales"],"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)\n\nlibrary(dplyr)\nlibrary(ggplot2)\nlibrary(patchwork)\nlibrary(facetious)\n```\n\n# facetious\n\n\u003c!-- badges: start --\u003e\n![](https://img.shields.io/badge/cool-useless-green.svg)\n\u003c!-- badges: end --\u003e\n\n`facetious` is home to some alternate facetting options for `ggplot2`.\n\n\n## What's in the box\n\n* `facet_wrap_strict()`\n    * respects nrow, ncol and inserts empty grobs to keep the resultant \n      plot at the given size\n    * Otherwise works like `ggplot2::facet_wrap()`\n* `facet_grid_blank()`\n    * When a factor level doesn't exist, this facetting approach will insert\n      a totally empty object, instead of just an empty plot\n    * Otherwise works like `ggplot2::facet_grid()`\n\n## Installation\n\nYou can install from [GitHub](https://github.com/coolbutuseless/facetious) with:\n\n``` r\n# install.package('remotes')\nremotes::install_github('coolbutuseless/facetious')\n```\n\n## `facet_wrap_strict`\n\nIn `ggplot2::facet_wrap()` (regardless of the `nrow` and `ncol` specified by the user),\nrows and columns of empty facets are removed.\n\nThis behaviour of `ggplot2` can make it difficult to size and align plots in multiple plots.\n\nIn contrast, `facetious::facet_wrap_strict()` will strictly adhere to the `nrow`, `ncol`\nspecified by the user, and retain blank rows/cols of facets.\n\n```{r}\nlibrary(ggplot2)\nlibrary(patchwork)\nlibrary(facetious)\n\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n# Standard ggplot2 facet_wrap()\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nggplot_facet_wrap \u003c- ggplot(mtcars) +\n  geom_point(aes(mpg, wt)) + \n  facet_wrap(~cyl, nrow = 3, ncol = 2) + \n  labs(title = \"facet_wrap(... nrow=3, ncol=2)\")\n\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n# facetious::facet_wrap_strict\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nfacetious_facet_wrap_strict \u003c- ggplot(mtcars) +\n  geom_point(aes(mpg, wt)) + \n  facet_wrap_strict(~cyl, nrow = 3, ncol = 2) + \n  labs(title = \"facet_wrap_strict(... nrow=3, ncol=2)\")\n\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n# Use 'patchwork' to stitch plots side-by-side\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nggplot_facet_wrap + facetious_facet_wrap_strict\n```\n\n\n## `facet_grid_blank`\n\nBy default when a particular factor level is empty, `ggplot2` includes an empty\nplot.\n\n`facetious::facet_grid_blank()` goes a step further and (by default) makes the\nempty facet entirely *blank*.\n\nThat is, empty factor levels are represented as a `grid::nullGrob()`, but it is\npossible to specify another grob, or list of grobs to fill the empty facets.\n\nv0.1.1 of `facetious` borrows an idea from the really great hack provided in \n[ggbillboard](https://github.com/nacnudus/ggbillboard) by [Duncan Garmonsway](https://twitter.com/nacnudus) - i.e. \ndon't just put empty grobs into empty facets, put some advertising in there! \n\n```{r}\nlibrary(dplyr)\nlibrary(ggplot2)\nlibrary(patchwork)\nlibrary(facetious)\n\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n# Make some data with some empty factors\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nplot_df \u003c- mtcars %\u003e%\n  mutate(\n    cyl = as.factor(cyl),\n    am = as.factor(am)\n  ) %\u003e%\n  filter(!(cyl == 4 \u0026 am == 1)) %\u003e%\n  filter(!(cyl == 8 \u0026 am == 0))\n\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n# Standard ggplot facet_grid()\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nggplot_facet_grid \u003c- ggplot(plot_df) +\n  geom_point(aes(mpg, wt)) +\n  facet_grid(rows = vars(cyl), cols = vars(am), drop = FALSE,\n             labeller = label_both) +\n  labs(title = \"ggplot2::facet_grid()\")\n\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n# facetious::facet_grid_blank()\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nfacetious_facet_grid_blank \u003c- ggplot(plot_df) +\n  geom_point(aes(mpg, wt)) +\n  facet_grid_blank(rows = vars(cyl), cols = vars(am), drop = FALSE, \n                   labeller = label_both) +\n  labs(title = \"facetious::facet_grid_blank()\")\n\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n# Use 'patchwork' to stitch plots side-by-side\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nggplot_facet_grid + facetious_facet_grid_blank\n```\n\n# Using alternate globs for blank facets. Example 1 - single grob\n\n\n```{r}\ngrob_for_blank \u003c- grid::textGrob(\"No data available\")\n\n ggplot(plot_df) +\n  geom_point(aes(mpg, wt)) +\n  facet_grid_blank(rows = vars(cyl), cols = vars(am), drop = FALSE, \n                   labeller = label_both, blank = grob_for_blank) +\n  labs(title = \"facetious::facet_grid_blank()\")\n\n```\n\n\n# Using alternate globs for blank facets. Example 2 - multiple grobs\n\n```{r fig.height = 8}\ngrobs_for_blank \u003c- list(\n  grid::rasterGrob(jpeg::readJPEG(\"man/figures/distracted.jpg\")),\n  grid::rasterGrob(jpeg::readJPEG(\"man/figures/run.jpg\"))\n)\n\n ggplot(plot_df) +\n  geom_point(aes(mpg, wt)) +\n  facet_grid_blank(rows = vars(cyl), cols = vars(am), drop = FALSE, \n                   labeller = label_both, blank = grobs_for_blank) +\n  labs(title = \"facetious::facet_grid_blank()\")\n\n```\n\n\n## Related Software\n\n* [ggplot2](https://cran.r-project.org/package=ggplot2)\n* [ggforce](https://cran.r-project.org/package=ggforce) a great package with alternate facets and\n  tools for ggplot2\n* [ggbillboard](https://github.com/nacnudus/ggbillboard) a package for replacing\n  blank facets with other grobs.  This was so cool that I've incorporated the \n  idea into `facetious` as part of the facet process, rather than as a post-processing\n  step.\n\n## Acknowledgements\n\n* R Core for developing and maintaining the language.\n* CRAN maintainers, for patiently shepherding packages onto CRAN and maintaining\n  the repository\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoolbutuseless%2Ffacetious","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoolbutuseless%2Ffacetious","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoolbutuseless%2Ffacetious/lists"}