{"id":16896254,"url":"https://github.com/clauswilke/relayer","last_synced_at":"2025-03-22T09:31:41.920Z","repository":{"id":69460131,"uuid":"133398771","full_name":"clauswilke/relayer","owner":"clauswilke","description":"Rethinking layers in ggplot2","archived":false,"fork":false,"pushed_at":"2018-05-16T15:49:22.000Z","size":179,"stargazers_count":74,"open_issues_count":3,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-15T02:11:57.572Z","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":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clauswilke.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":"2018-05-14T17:35:01.000Z","updated_at":"2024-11-01T19:11:58.000Z","dependencies_parsed_at":"2023-03-11T06:07:49.982Z","dependency_job_id":null,"html_url":"https://github.com/clauswilke/relayer","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/clauswilke%2Frelayer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clauswilke%2Frelayer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clauswilke%2Frelayer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clauswilke%2Frelayer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clauswilke","download_url":"https://codeload.github.com/clauswilke/relayer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244937751,"owners_count":20535124,"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-13T17:29:32.026Z","updated_at":"2025-03-22T09:31:41.574Z","avatar_url":"https://github.com/clauswilke.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, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\"\n)\n```\n\n# relayer\n\nRethinking layers in ggplot2, written by Claus O. Wilke\n\n\n## Installation\n\n```\ndevtools::install_github(\"clauswilke/relayer\")\n```\nThis is an experimental package. Use at your own risk. API is not stable. No user support provided.\n\n## Examples\n\nLoad required packages:\n```{r message = FALSE}\nlibrary(ggplot2) # version 2.3.0 required\nlibrary(dplyr)\nlibrary(relayer)\n```\n\nMake a layer with its own fill scale:\n\n```{r}\ndf1 \u003c- data.frame(x = c(1, 2, 3))\n\nggplot(df1, aes(x = x)) +\n  geom_tile(aes(fill = x, y = 2)) +\n  geom_tile(aes(fill2 = x, y = 1)) %\u003e% rename_geom_aes(new_aes = c(\"fill\" = \"fill2\")) +\n  scale_colour_viridis_c(aesthetics = \"fill\", guide = \"legend\", name = \"viridis A\", option = \"A\") +\n  scale_colour_viridis_c(aesthetics = \"fill2\", guide = \"legend\", name = \"viridis D\")\n```\n\nMake several layers with their own color scales:\n\n```{r fig.width = 10}\n# make color scale shortcut\nscale_distiller \u003c- function(aesthetics, palette, name, ...) {\n  scale_colour_distiller(\n    aesthetics = aesthetics,\n    palette = palette,\n    name = name, ...,\n    guide = guide_legend(order = palette))\n}\n\n# subset data\niris_setosa \u003c- filter(iris, Species == \"setosa\")\niris_versicolor \u003c- filter(iris, Species == \"versicolor\")\niris_virginica \u003c- filter(iris, Species == \"virginica\")\n\n# plot\nggplot(mapping = aes(Sepal.Length, Sepal.Width)) +\n  (geom_point(data = iris_setosa, aes(colour1 = Sepal.Width)) %\u003e%\n     rename_geom_aes(new_aes = c(\"colour\" = \"colour1\"))) +\n  (geom_point(data = iris_versicolor, aes(colour2 = Sepal.Width)) %\u003e%\n     rename_geom_aes(new_aes = c(\"colour\" = \"colour2\"))) +\n  (geom_point(data = iris_virginica, aes(colour3 = Sepal.Width)) %\u003e%\n     rename_geom_aes(new_aes = c(\"colour\" = \"colour3\"))) +\n  facet_wrap(~Species) +\n  scale_distiller(\"colour1\", 5, \"setosa\") +\n  scale_distiller(\"colour2\", 6, \"versicolor\") +\n  scale_distiller(\"colour3\", 7, \"virginica\") +\n  theme_bw() +\n  theme(legend.position = \"bottom\")\n```\n\nUse multiple color scales within a single layer. Note the difference to the previous example: Now the three color scales are jointly trained to the union of the data values.\n\n```{r fig.width = 10}\nggplot(iris, aes(Sepal.Length, Sepal.Width)) +\n  geom_point(aes(col1 = Sepal.Width, col2 = Sepal.Width, col3 = Sepal.Width, group = Species)) %\u003e%\n    rename_geom_aes(\n      new_aes = c(\"colour\" = \"col1\", \"colour\" = \"col2\", \"colour\" = \"col3\"),\n      aes(colour = case_when(group == 1 ~ col1, group == 2 ~ col2, TRUE ~ col3))\n    ) +\n    facet_wrap(~Species) +\n    scale_distiller(\"col1\", 5, \"setosa\") +\n    scale_distiller(\"col2\", 6, \"versicolor\") +\n    scale_distiller(\"col3\", 7, \"virginica\") +\n    theme_bw() + theme(legend.position = \"bottom\", legend.key.width = grid::unit(6, \"pt\"))\n```\n\nSwap `colour` and `fill` aesthetics in a geom:\n```{r}\nggplot(iris, aes(Sepal.Length, fill = Species)) +\n  geom_density(colour = \"gray70\", size = 2, alpha = 0.7) %\u003e%\n  rename_geom_aes(new_aes = c(\"fill\" = \"colour\", \"colour\" = \"fill\"))\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclauswilke%2Frelayer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclauswilke%2Frelayer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclauswilke%2Frelayer/lists"}