{"id":13711127,"url":"https://github.com/davidsjoberg/ggbump","last_synced_at":"2025-05-06T20:32:02.949Z","repository":{"id":45847891,"uuid":"242713112","full_name":"davidsjoberg/ggbump","owner":"davidsjoberg","description":"A geom for ggplot to create bump plots","archived":false,"fork":false,"pushed_at":"2024-04-03T16:50:03.000Z","size":14473,"stargazers_count":523,"open_issues_count":15,"forks_count":31,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-08-03T23:23:18.178Z","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/davidsjoberg.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":"2020-02-24T10:59:44.000Z","updated_at":"2024-08-02T19:23:00.000Z","dependencies_parsed_at":"2024-01-17T16:08:12.307Z","dependency_job_id":"ccb48aea-1844-4db3-9cf4-e373358bbb8e","html_url":"https://github.com/davidsjoberg/ggbump","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/davidsjoberg%2Fggbump","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidsjoberg%2Fggbump/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidsjoberg%2Fggbump/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidsjoberg%2Fggbump/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidsjoberg","download_url":"https://codeload.github.com/davidsjoberg/ggbump/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224528341,"owners_count":17326347,"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:04.761Z","updated_at":"2024-11-13T21:31:32.722Z","avatar_url":"https://github.com/davidsjoberg.png","language":"R","funding_links":[],"categories":["Plot layers","R","ggplot"],"sub_categories":["Additional Plot Types"],"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  echo = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\",\n  dpi = 800\n)\n```\n# ggbump \u003cimg src=\"man/figures/logo.png\" align=\"right\" /\u003e\n\n\u003c!-- badges: start --\u003e\n[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing)\n[![CRAN status](https://www.r-pkg.org/badges/version/ggbump)](https://CRAN.R-project.org/package=ggbump)\n[![R build status](https://github.com/davidsjoberg/ggbump/workflows/R-CMD-check/badge.svg)](https://github.com/davidsjoberg/ggbump/actions)\n[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/ggbump)](https://cranlogs.r-pkg.org/badges/ggbump)\n\u003c!-- badges: end --\u003e\n\nThe R package `ggbump` creates elegant bump charts in ggplot. Bump charts are good\nto use to \nplot ranking over time, or other examples when the path between \ntwo nodes have no statistical significance. Also includes functions to create\ncustom smooth lines called sigmoid curves.\n\n## Installation\n\nYou can install ggbump from CRAN with:\n\n``` r\ninstall.packages(\"ggbump\")\n```\n\nOr the latest development version from [github](https://github.com/davidsjoberg/ggbump) with:\n\n``` r\ndevtools::install_github(\"davidsjoberg/ggbump\")\n```\n\n## Bump chart examples\n\nBasic example:\n\n```{r main_plot, fig.height=3, fig.width = 9, echo = FALSE, warning=FALSE, message=FALSE}\nif(!require(pacman)) install.packages(\"pacman\")\npacman::p_load(tidyverse, cowplot, wesanderson, ggbump)\n\ndf \u003c- tibble(country = c(\"India\", \"India\", \"India\", \"Sweden\", \"Sweden\", \"Sweden\", \"Germany\", \"Germany\", \"Germany\", \"Finland\", \"Finland\", \"Finland\"),\n             year = c(2011, 2012, 2013, 2011, 2012, 2013, 2011, 2012, 2013, 2011, 2012, 2013),\n             rank = c(4, 2, 2, 3, 1, 4, 2, 3, 1, 1, 4, 3))\n\nggplot(df, aes(year, rank, color = country)) +\n  geom_point(size = 7) +\n  geom_text(data = df %\u003e% filter(year == min(year)),\n            aes(x = year - .1, label = country), size = 5, hjust = 1) +\n  geom_text(data = df %\u003e% filter(year == max(year)),\n            aes(x = year + .1, label = country), size = 5, hjust = 0) +\n  geom_bump(size = 2, smooth = 8) +\n  scale_x_continuous(limits = c(2010.6, 2013.4),\n                     breaks = seq(2011, 2013, 1)) +\n  theme_minimal_grid(font_size = 14, line_size = 0) +\n  theme(legend.position = \"none\",\n        panel.grid.major = element_blank()) +\n  labs(y = \"RANK\",\n       x = NULL) +\n  scale_y_reverse() +\n  scale_color_manual(values = wes_palette(n = 4, name = \"GrandBudapest1\"))\n\n```\n\nA more advanced example:\n\n![Example2](https://user-images.githubusercontent.com/44140737/75692519-fb146b00-5ca5-11ea-85f5-9fc33e760a7d.png)\n\n[Click here for code to the plot above](https://github.com/davidsjoberg/ggbump/wiki/My-year-on-Spotify)\n\nFlags could be used instead of names:\n\n![Example3](https://user-images.githubusercontent.com/44140737/76630573-8f04f300-6540-11ea-802a-653e3b509dfa.png)\n\n[Click here for code to the plot above](https://github.com/davidsjoberg/ggbump/wiki/geom_bump-with-flags)\n\n## Sigmoid curves examples\n\nWith `geom_sigmoid` you can make custom sigmoid curves:\n\n![Example4](https://user-images.githubusercontent.com/44140737/79050627-9268c880-7c2b-11ea-9afb-263cce8f98f3.png)\n\n[Click here for code to the plot above](https://github.com/davidsjoberg/ggbump/wiki/geom_sigmoid)\n\nWith `geom_sigmoid` you have the flexibility to make more complex plots:\n \n![Example5](man/figures/ranking_gdpr.png?raw=true)\n\n[Click here for code to the plot above](https://github.com/davidsjoberg/tidytuesday/blob/master/2020w17/2020w17_skript.R)\n\n# Tutorial\n\n## Prep\n\nLoad packages and get some data with rank:\n\n```{r data}\nif(!require(pacman)) install.packages(\"pacman\")\nlibrary(ggbump)\npacman::p_load(tidyverse, cowplot, wesanderson)\n\ndf \u003c- tibble(country = c(\"India\", \"India\", \"India\", \"Sweden\", \"Sweden\", \"Sweden\", \"Germany\", \"Germany\", \"Germany\", \"Finland\", \"Finland\", \"Finland\"),\n             year = c(2011, 2012, 2013, 2011, 2012, 2013, 2011, 2012, 2013, 2011, 2012, 2013),\n             value = c(492, 246, 246, 369, 123, 492, 246, 369, 123, 123, 492, 369))\n\nknitr::kable(head(df))\n```\n\nTo create a ranking column we use `rank` from base R. We specify `ties.method = \"random\"` to make sure that each country have different rankings if they have the same value.\n\n```{r}\ndf \u003c- df %\u003e% \n  group_by(year) %\u003e% \n  mutate(rank = rank(value, ties.method = \"random\")) %\u003e% \n  ungroup()\n\nknitr::kable(head(df))\n```\n\n\n## Make a bump chart\n\nMost simple use case:\n\n```{r pressure, echo = TRUE, fig.height=3, fig.width = 9}\nggplot(df, aes(year, rank, color = country)) +\n    geom_bump()\n```\n\n## Pimp the bump chart!\n\nImprove the bump chart by adding:\n\n* A point for each rank observation.\n* Choose a minimal theme, I use `theme_minimal_grid()` from `cowplot`.\n* Choose nice colors so it does not look generic ggplot. I use a palette from `wesanderson`.\n* Remove legend and add labels at the start and end of the bumpy ride.\n* Reverse the y-axis to get rank 1 at the top.\n* Adjust the 'smoothness' of the lines by setting `smooth` to 8. Higher means less smooth.\n\n```{r, fig.height=3, fig.width = 9, echo = TRUE}\n\nggplot(df, aes(year, rank, color = country)) +\n  geom_point(size = 7) +\n  geom_text(data = df %\u003e% filter(year == min(year)),\n            aes(x = year - .1, label = country), size = 5, hjust = 1) +\n  geom_text(data = df %\u003e% filter(year == max(year)),\n            aes(x = year + .1, label = country), size = 5, hjust = 0) +\n  geom_bump(size = 2, smooth = 8) +\n  scale_x_continuous(limits = c(2010.6, 2013.4),\n                     breaks = seq(2011, 2013, 1)) +\n  theme_minimal_grid(font_size = 14, line_size = 0) +\n  theme(legend.position = \"none\",\n        panel.grid.major = element_blank()) +\n  labs(y = \"RANK\",\n       x = NULL) +\n  scale_y_reverse() +\n  scale_color_manual(values = wes_palette(n = 4, name = \"GrandBudapest1\"))\n```\n\n## geom_bump with factors (development version only)\n\nYou can use `geom_bump` with factors or character as x axis. Just remember to keep an eye on factor order. \n\n```{r, fig.height=2.5, fig.width = 7, echo = TRUE}\n# Original df\ndf \u003c- tibble(season = c(\"Spring\", \"Pre-season\", \"Summer\", \"Season finale\", \"Autumn\", \"Winter\", \n                        \"Spring\", \"Pre-season\", \"Summer\", \"Season finale\", \"Autumn\", \"Winter\", \n                        \"Spring\", \"Pre-season\", \"Summer\", \"Season finale\", \"Autumn\", \"Winter\",\n                        \"Spring\", \"Pre-season\", \"Summer\", \"Season finale\", \"Autumn\", \"Winter\"),\n             rank = c(1, 3, 4, 2, 1, 4,\n                      2, 4, 1, 3, 2, 3,\n                      4, 1, 2, 4, 4, 1,\n                      3, 2, 3, 1, 3, 2),\n             player = c(rep(\"David\", 6),\n                        rep(\"Anna\", 6),\n                        rep(\"Franz\", 6),\n                        rep(\"Ika\", 6)))\n\n# Create factors and order factor\ndf \u003c- df %\u003e% \n  mutate(season = factor(season, levels = unique(season)))\n\n# Add manual axis labels to plot\nggplot(df, aes(season, rank, color = player)) +\n  geom_bump(size = 2, smooth = 20, show.legend = F) +\n  geom_point(size = 5, aes(shape = player)) +\n  theme_minimal_grid(font_size = 10, line_size = 0) +\n  theme(panel.grid.major = element_blank(),\n        axis.ticks = element_blank()) +\n  scale_color_manual(values = wes_palette(n = 4, name = \"IsleofDogs1\"))\n\n```\n\n\n## Feedback\n\nIf you find any error or have suggestions for improvements you are more than welcome to contact me :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidsjoberg%2Fggbump","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidsjoberg%2Fggbump","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidsjoberg%2Fggbump/lists"}