{"id":19496647,"url":"https://github.com/yjunechoe/ggcolormeter","last_synced_at":"2025-04-25T22:31:23.276Z","repository":{"id":43458836,"uuid":"502875934","full_name":"yjunechoe/ggcolormeter","owner":"yjunechoe","description":"A ggplot2 color/fill legend guide extension in the style of a dashboard meter","archived":false,"fork":false,"pushed_at":"2024-01-23T14:00:14.000Z","size":5383,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-07-17T09:55:47.927Z","etag":null,"topics":["ggplot2","package"],"latest_commit_sha":null,"homepage":"https://yjunechoe.github.io/ggcolormeter/","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/yjunechoe.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,"dei":null}},"created_at":"2022-06-13T08:46:02.000Z","updated_at":"2024-06-24T16:04:53.000Z","dependencies_parsed_at":"2024-01-07T01:44:55.750Z","dependency_job_id":"10b47bae-44d3-408d-a9bc-aed4c2aa8eee","html_url":"https://github.com/yjunechoe/ggcolormeter","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/yjunechoe%2Fggcolormeter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjunechoe%2Fggcolormeter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjunechoe%2Fggcolormeter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjunechoe%2Fggcolormeter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yjunechoe","download_url":"https://codeload.github.com/yjunechoe/ggcolormeter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224019555,"owners_count":17242175,"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":["ggplot2","package"],"created_at":"2024-11-10T21:41:44.706Z","updated_at":"2024-11-10T21:41:46.049Z","avatar_url":"https://github.com/yjunechoe.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  dev.args = list(png = list(type = \"cairo\")),\n  fig.retina = 2\n)\n```\n\n# ggcolormeter\n\n\u003c!-- badges: start --\u003e\n[![](https://img.shields.io/badge/devel%20version-`r as.character(packageVersion('ggcolormeter'))`-gogreen.svg)](https://github.com/yjunechoe/ggcolormeter)\n[![R-CMD-check](https://github.com/yjunechoe/ggcolormeter/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/yjunechoe/ggcolormeter/actions/workflows/R-CMD-check.yaml)\n[![Codecov test coverage](https://codecov.io/gh/yjunechoe/ggcolormeter/branch/main/graph/badge.svg)](https://app.codecov.io/gh/yjunechoe/ggcolormeter?branch=main)\n\u003c!-- badges: end --\u003e\n\nThe `{ggcolormeter}` package provides a single function [`guide_colormeter()`](https://yjunechoe.github.io/ggcolormeter/reference/guide_colormeter.html), which is a `{ggplot2}` color/fill legend **guide extension** in the style of a dashboard meter.\n\n## Installation\n\n```{r, eval=FALSE}\ninstall.packages(\"ggcolormeter\")\n# or\nremotes::install_github(\"yjunechoe/ggcolormeter\")\n```\n\n\n## Simple usage\n\n```{r simple-usage}\nlibrary(ggplot2)\nlibrary(ggcolormeter)\n\ntheme_set(theme_classic())\n\np \u003c- ggplot(mtcars, aes(drat, hp)) +\n  geom_point(aes(color = mpg))\n\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(10),\n    guide = guide_colormeter()\n  )\n```\n\n# Colormeter guide theme components\n\nThe colormeter guide has argument families for styling 5 distinct components of the guide:\n\n1) [Size and aspect](https://github.com/yjunechoe/ggcolormeter#1-size-and-aspect)\n2) [Arc](https://github.com/yjunechoe/ggcolormeter#2-arc)\n3) [Label](https://github.com/yjunechoe/ggcolormeter#3-label)\n4) [Dashboard](https://github.com/yjunechoe/ggcolormeter#4-dashboard)\n5) [Frame](https://github.com/yjunechoe/ggcolormeter#5-frame)\n\nPosition of these theme elements is relative to the [guide-internal coordinate system](https://yjunechoe.github.io/ggcolormeter/reference/legend-coords.html), which you can inspect with the `debug = TRUE` argument.\n\n## 1) Size and aspect\n\nThe colormeter legend is a bit pecular in that its size doesn't expand with more keys: the colormeter has a fixed size and shape, and its elements are packed inside it.\n\nYou can primarily control the size of the legend with `legend_size` and `aspect.ratio`\n\n```{r}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(10),\n    guide = guide_colormeter(\n      legend_size = unit(3, \"cm\"),\n      aspect.ratio = .8\n    )\n  )\n```\n\nNote that the usual legend background is still present and different from the dashboard circle:\n\n```{r}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(10),\n    guide = guide_colormeter(\n      legend_size = unit(3, \"cm\"),\n      aspect.ratio = .8\n    )\n  ) +\n  theme(legend.background = element_rect(color = \"red\", fill = \"pink\"))\n```\n\nMost of the time you'd want to remove this legend background, as the dashboard serves that purpose:\n\n```{r}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(10),\n    guide = guide_colormeter(\n    )\n  ) +\n  theme(\n    legend.position = c(.85, .75),\n    legend.background = element_blank()\n  )\n```\n\n## 2) Arc\n\n```{r}\nformals(guide_colormeter)[grepl(\"arc\", names(formals(guide_colormeter)))]\n```\n\nNon-positional aesthetic arguments for the color arc:\n\n```{r arc-theme}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(10),\n    guide = guide_colormeter(\n      arc_width = 1/6, # thinner arcs\n      arc_gap = 1/3, # bigger gaps\n      arc_rounding = 0.03 # rounded corners\n    )\n  )\n```\n\nBy default, label and dashboard radii are derived from `arc_radius`:\n\n```{r arc-radius}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(10),\n    guide = guide_colormeter(\n      arc_radius = 1.2\n    )\n  )\n```\n\nYou can use `arc_range` to set the start and end angles of the color meter, which may yield different shapes:\n\n```{r}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(5), # half the arcs\n    guide = guide_colormeter(\n      arc_range = c(-pi/2, 0) # quarter circle\n    )\n  )\n```\n\nThe defaults aren't great for when you change from the dashboard shape. Some manual adjustments may be desirable:\n\n```{r}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(5),\n    guide = guide_colormeter(\n      arc_range = c(-pi/2, 0),\n      title_position = c(-.2, .2), # moves title left and up from center\n      legend_padding = grid::unit(0.7, \"lines\") # pads relative to legend label\n    )\n  )\n```\n\n## 3) Label\n\n```{r}\nformals(guide_colormeter)[grepl(\"label\", names(formals(guide_colormeter)))]\n```\n\nBy default, the dashboard radius is derived from `label_radius`:\n\n```{r}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(10),\n    guide = guide_colormeter(\n      label_radius = 1.5\n    )\n  )\n```\n\nLike `ggplot2::guide_colorsteps()`, the argument `show.limits` controls labeling the limits of the scale:\n\n```{r}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(10),\n    guide = guide_colormeter(\n      label_radius = 1.3,\n      show.limits = TRUE\n    )\n  )\n```\n\n## 4) Dashboard\n\n```{r}\nformals(guide_colormeter)[grepl(\"dashboard\", names(formals(guide_colormeter)))]\n```\n\n`dashboard_radius` controls the radius of just the dashboard circle\n\n```{r}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(10),\n    guide = guide_colormeter(\n      dashboard_radius = 1.2,\n    )\n  )\n```\n\nBy default, the dashboard is clipped to the legend boundary, which can be turned off:\n\n```{r}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(10),\n    guide = guide_colormeter(\n      title = \"mpg\u003cbr\u003e\u003cbr\u003e\n        \u003cspan style='color:darkgrey;font-size:12px'\u003emiles per gallon\u003c/span\u003e\",\n      clip_dashboard = FALSE\n    )\n  ) +\n  theme(legend.title = ggtext::element_markdown(vjust = -.6))\n```\n\nNon-positional aesthetic arguments for the dashboard:\n\n```{r}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(10),\n    guide = guide_colormeter(\n      dashboard_fill = \"skyblue\",\n      dashboard_color = \"steelblue\",\n      dashboard_linetype = 5,\n      dashboard_linewidth = 4\n    )\n  )\n```\n\n## 5) Frame\n\n```{r}\nformals(guide_colormeter)[grepl(\"frame\", names(formals(guide_colormeter)))]\n```\n\nFrames simply decorate the color arcs/bars:\n\n```{r}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(10),\n    guide = guide_colormeter(\n      frame_color = \"black\",\n      frame_linewidth = .3\n    )\n  )\n```\n\n## Miscellaneous\n\nSet `debug = TRUE` to inspect the internal legend coordinate system (for deciding on `dashboard_radius`, `arc_width`, `title_position`, etc.):\n\n```{r}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(10),\n    guide = guide_colormeter(debug = TRUE)\n  )\n```\n\nPuttings labels inside the arc:\n\n```{r}\np +\n  scale_color_viridis_c(\n    option = \"inferno\",\n    breaks = scales::breaks_pretty(5),\n    guide = guide_colormeter(\n      arc_width = 0.1,\n      label_radius = .7,\n      aspect.ratio = 1.1,\n      dashboard_color = NA\n    )\n  ) +\n  theme(legend.position = c(.85, .75))\n```\n\n## Acknowledgments\n\n- Thomas Lin Pedersen for [`{ggforce}`](https://github.com/thomasp85/ggforce), whose several unexported functions are used in this package.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjunechoe%2Fggcolormeter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyjunechoe%2Fggcolormeter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjunechoe%2Fggcolormeter/lists"}