{"id":13711226,"url":"https://github.com/MattCowgill/ggdirectlabel","last_synced_at":"2025-05-06T20:32:31.352Z","repository":{"id":38849102,"uuid":"447056733","full_name":"MattCowgill/ggdirectlabel","owner":"MattCowgill","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-11T05:33:16.000Z","size":1452,"stargazers_count":41,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-08-03T23:23:21.543Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MattCowgill.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":"2022-01-12T02:57:11.000Z","updated_at":"2024-02-10T00:46:01.000Z","dependencies_parsed_at":"2024-01-17T16:56:51.581Z","dependency_job_id":"de3d3915-6068-4587-ad55-93298b4de930","html_url":"https://github.com/MattCowgill/ggdirectlabel","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/MattCowgill%2Fggdirectlabel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattCowgill%2Fggdirectlabel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattCowgill%2Fggdirectlabel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattCowgill%2Fggdirectlabel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MattCowgill","download_url":"https://codeload.github.com/MattCowgill/ggdirectlabel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224528365,"owners_count":17326349,"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.942Z","updated_at":"2024-11-13T21:31:40.293Z","avatar_url":"https://github.com/MattCowgill.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 = 2\n)\n```\n\n# ggdirectlabel\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/MattCowgill/ggdirectlabel/workflows/R-CMD-check/badge.svg)](https://github.com/MattCowgill/ggdirectlabel/actions)\n[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)\n[![R-CMD-check](https://github.com/MattCowgill/ggdirectlabel/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/MattCowgill/ggdirectlabel/actions/workflows/R-CMD-check.yaml)\n\u003c!-- badges: end --\u003e\n\nThe goal of ggdirectlabel is to make it easier to directly label ggplot2 charts rather than using legends.\n\n## Installation\n\nYou can install the development version of ggdirectlabel from [GitHub](https://github.com/) with:\n\n``` r\n# install.packages(\"devtools\")\ndevtools::install_github(\"MattCowgill/ggdirectlabel\")\n```\n\n```{r}\nlibrary(ggdirectlabel)\nlibrary(ggplot2)\nlibrary(magrittr)\n```\n\n## Using `geom_richlegend()`\nHere's a standard ggplot2 scatterplot:\n```{r}\nbase_scatter \u003c- mtcars |\u003e \n  ggplot(aes(x = wt, y = mpg, col = factor(cyl))) +\n  geom_point()\n\nbase_scatter\n```\n\nThis is fine! But sometimes you might like the legend levels (4, 6, and 8 in this example) to be coloured according to the levels in the data. That's where `geom_richlegend()` comes in:\n```{r}\nbase_scatter +\n  geom_richlegend(aes(label = cyl)) +\n  theme(legend.position = \"none\")\n```\n\nYou can move the 'rich legend' around:\n```{r}\nbase_scatter +\n  geom_richlegend(aes(label = cyl),\n                  legend.position = \"bottomleft\",\n                  vjust = 0,\n                  hjust = 0) +\n  theme(legend.position = \"none\")\n```\n\n`geom_richlegend()` respects facets - it'll place a little legend annotation for each level of the data that appears in that panel:\n\n```{r}\nbase_scatter +\n  geom_richlegend(aes(label = paste0(cyl, \" cylinders\"))) +\n  facet_wrap(~cyl)\n```\n\n\n## Using `geom_linepoint()`\n\nWithout ggirectlabel, we might do something like:\n\n```{r no-directlabel}\n\nggplot2::economics_long %\u003e%\n  ggplot(aes(x = date, y = value, col = variable)) +\n  geom_line() +\n  geom_point(data = ~dplyr::filter(., date == max(date)),\n             fill = \"white\",\n             shape = 21,\n             size = 2.5,\n             stroke = 1.25)\n```\n\nThis is fine! But this is a more straightforward way to achieve the same thing:\n\n```{r example}\nggplot2::economics_long %\u003e%\n  ggplot(aes(x = date, y = value, col = variable)) +\n  geom_linepoint()\n```\n\n## Using `scale_x_date_rightalign()`\n\nIn time series line charts, it's often important to make clear the date of \nyour most recent observation. The `scale_x_date_rightalign()` function aligns\nthe breaks of your x-axis so that the most recent observation is included in \nthe breaks.\n\n```{r scale_x_date_rightalign}\nggplot2::economics_long %\u003e%\n  ggplot(aes(x = date, y = value, col = variable)) +\n  geom_linepoint() +\n  scale_x_date_rightalign()\n```\n\n## Using `geom_finallabel()`\n\nIn time series line charts, you may wish to label the final point in the series. The `geom_finallabel()` function makes that easy. \n\n```{r geom_finallabel}\nggplot2::economics_long %\u003e%\n  ggplot(aes(x = date, y = value, col = variable)) +\n  geom_linepoint() +\n  geom_finallabel(aes(label = round(value, 0))) +\n  scale_x_date_rightalign(expand = expansion(c(0, 0.15))) +\n  theme(legend.position = \"none\")\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMattCowgill%2Fggdirectlabel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMattCowgill%2Fggdirectlabel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMattCowgill%2Fggdirectlabel/lists"}