{"id":13712007,"url":"https://github.com/marcboschmatas/ggspark","last_synced_at":"2025-10-22T04:42:26.083Z","repository":{"id":239004996,"uuid":"798229840","full_name":"marcboschmatas/ggspark","owner":"marcboschmatas","description":"ggplot2 Functions to Create Tufte Style Sparklines","archived":false,"fork":false,"pushed_at":"2024-05-13T12:58:58.000Z","size":238,"stargazers_count":8,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-26T08:38:22.220Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcboschmatas.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2024-05-09T11:03:27.000Z","updated_at":"2024-09-16T10:09:46.000Z","dependencies_parsed_at":"2024-06-28T10:16:07.720Z","dependency_job_id":null,"html_url":"https://github.com/marcboschmatas/ggspark","commit_stats":null,"previous_names":["marcboschmatas/ggspark"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcboschmatas%2Fggspark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcboschmatas%2Fggspark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcboschmatas%2Fggspark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcboschmatas%2Fggspark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcboschmatas","download_url":"https://codeload.github.com/marcboschmatas/ggspark/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224535701,"owners_count":17327575,"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:13.975Z","updated_at":"2025-10-22T04:42:21.043Z","avatar_url":"https://github.com/marcboschmatas.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)\n```\n\n# ggspark\n\n\u003c!-- badges: start --\u003e\n\u003c!-- badges: end --\u003e\n\nThe goal of ggspark is to help create ggplot2 functions that help with creating sparkline plots in the style of Edward Tufte, such as this one\n\n![Original sparklines, source Edward Tufte.](https://s3.amazonaws.com/edwardtufte.com/sparklines_hemodynamics_3.jpg)\n\nThus, the package has two main functions: `stat_interquartilerange()` that draws a `geom_ribbon()` between the 1st and 3rd quartile of the variable in the y axis, and `stat_sparklabels()` that draws points or text labels in the beginning, min, max, and end points of the variable in the y axis.\n\n## Installation\n\nYou can install the development version of ggspark like so:\n\n``` r\ndevtools::install_github(\"marcboschmatas/ggspark\")\n```\n\n## Example\n\nThe `stat_sparklabels()` function needs a colour scale with three values. The first one will be using for the start and end points of the line, the second one for the max, and the third one for the min.\n\n\n```{r example}\nlibrary(ggplot2)\nlibrary(ggspark)\nggplot(airquality, aes(Day, Wind, group = Month)) + \n  stat_interquartilerange(geom = \"ribbon\",\n                          show.legend = FALSE) +\n  geom_line() + \n  stat_sparklabels(geom = \"label\",\n                   show.legend = FALSE) + \n  scale_colour_manual(\"\", values = c(\"black\", \"blue\", \"red\")) + \n  scale_y_continuous(limits = c(0, 25)) + \n  facet_grid(Month~.) +\n  ggtitle(\"Daily wind intensity by month in NYC\") +\n  theme_minimal() + \n  theme(panel.grid = element_blank(),\n        axis.ticks = element_line())\n```\nIt has an optional `label_fun` parameter that allows to modify the label aesthetics (such as rounding, adding percentage or currency suffixes and prefixes...).\n\n```{r example2}\nlibrary(ggplot2)\nlibrary(ggspark)\nggplot(airquality, aes(Day, Wind, group = Month)) + \n  stat_interquartilerange(geom = \"ribbon\",\n                          show.legend = FALSE) +\n  geom_line() + \n  stat_sparklabels(geom = \"label\", label_fun = \\(x) round(x, 0),\n                   show.legend = FALSE) + \n  scale_colour_manual(\"\", values = c(\"black\", \"blue\", \"red\")) + \n  scale_y_continuous(limits = c(0, 25)) + \n  facet_grid(Month~.) +\n  ggtitle(\"Daily wind intensity by month in NYC\") +\n  theme_minimal() + \n  theme(panel.grid = element_blank(),\n        axis.ticks = element_line())\n```\n\n\nIt is also possible to use points instead of labels.\n\n```{r example3}\nlibrary(ggrepel)\nggplot(airquality, aes(Day, Wind, group = Month)) + \n  stat_interquartilerange(geom = \"ribbon\",\n                          show.legend = FALSE) +\n  geom_line() + \n  stat_sparklabels(geom = \"point\",\n                   show.legend = FALSE) + \n  scale_colour_manual(\"\", values = c(\"black\", \"blue\", \"red\")) + \n  scale_y_continuous(limits = c(0, 25)) + \n  facet_grid(Month~.) +\n  ggtitle(\"Daily wind intensity by month in NYC\") +\n  theme_minimal() + \n  theme(panel.grid = element_blank(),\n        axis.ticks = element_line())\n```\n\nWith ggrepel, it is possible to combine both text and dots.\n\n```{r example4}\nlibrary(ggrepel)\nggplot(airquality, aes(Day, Wind, group = Month)) + \n  stat_interquartilerange(geom = \"ribbon\",\n                          show.legend = FALSE) +\n  geom_line() + \n  stat_sparklabels(geom = \"point\", label_fun = \\(x) round(x, 0),\n                   show.legend = FALSE) + \n    stat_sparklabels(geom = \"text_repel\", label_fun = \\(x) round(x, 0),\n                   show.legend = FALSE) + \n  scale_colour_manual(\"\", values = c(\"black\", \"blue\", \"red\")) + \n  scale_y_continuous(limits = c(0, 25)) + \n  facet_grid(Month~.) +\n  ggtitle(\"Daily wind intensity by month in NYC\") +\n  theme_minimal() + \n  theme(panel.grid = element_blank(),\n        axis.ticks = element_line())\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcboschmatas%2Fggspark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcboschmatas%2Fggspark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcboschmatas%2Fggspark/lists"}