{"id":33187095,"url":"https://mrcaseb.github.io/ggpath/","last_synced_at":"2025-11-25T18:00:38.338Z","repository":{"id":58693851,"uuid":"489932854","full_name":"mrcaseb/ggpath","owner":"mrcaseb","description":"Robust Image Rendering Support for 'ggplot2'","archived":false,"fork":false,"pushed_at":"2025-10-16T09:53:48.000Z","size":31949,"stargazers_count":47,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-31T00:53:57.855Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://mrcaseb.github.io/ggpath/","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/mrcaseb.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"mrcaseb","patreon":null,"open_collective":null,"ko_fi":"mrcaseb","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2022-05-08T12:08:37.000Z","updated_at":"2025-10-23T08:01:14.000Z","dependencies_parsed_at":"2024-01-18T04:08:01.662Z","dependency_job_id":"27ad59e7-5058-4691-b7ca-2606d5120f6a","html_url":"https://github.com/mrcaseb/ggpath","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/mrcaseb/ggpath","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrcaseb%2Fggpath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrcaseb%2Fggpath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrcaseb%2Fggpath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrcaseb%2Fggpath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrcaseb","download_url":"https://codeload.github.com/mrcaseb/ggpath/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrcaseb%2Fggpath/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286079811,"owners_count":27282121,"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","status":"online","status_checked_at":"2025-11-25T02:00:05.816Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-11-16T05:00:30.371Z","updated_at":"2025-11-25T18:00:38.328Z","avatar_url":"https://github.com/mrcaseb.png","language":"R","funding_links":["https://github.com/sponsors/mrcaseb","https://ko-fi.com/mrcaseb"],"categories":["Icons, patterns and images"],"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# ggpath\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version/ggpath)](https://CRAN.R-project.org/package=ggpath)\n[![CRAN downloads](https://cranlogs.r-pkg.org/badges/grand-total/ggpath)](https://CRAN.R-project.org/package=ggpath)\n[![Dev status](https://img.shields.io/github/r-package/v/mrcaseb/ggpath/main?label=dev%20version\u0026style=flat-square\u0026logo=github)](https://mrcaseb.github.io/ggpath/)\n[![R-CMD-check](https://img.shields.io/github/actions/workflow/status/mrcaseb/ggpath/R-CMD-check.yaml?label=R%20check\u0026style=flat-square\u0026logo=github)](https://github.com/mrcaseb/ggpath/actions/workflows/R-CMD-check.yaml)\n[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)\n[![Codecov test coverage](https://codecov.io/gh/mrcaseb/ggpath/graph/badge.svg)](https://app.codecov.io/gh/mrcaseb/ggpath)\n\u003c!-- badges: end --\u003e\n\nggpath is a 'ggplot2' extension that enables robust image grobs in panels and theme elements. This means it helps plotting images (from local paths, from urls or from raw image data) in nearly every part of a ggplot. \n\n## Installation\n\nThe easiest way to get ggpath is to install it from [CRAN](https://cran.r-project.org/package=ggpath) with:\n\n``` r\ninstall.packages(\"ggpath\")\n```\n\nTo get a bug fix or to use a feature from the development version, you can install the development version of ggpath from [GitHub](https://github.com/mrcaseb/ggpath), for example with:\n\n```{r eval=FALSE}\nif (!require(\"pak\")) install.packages(\"pak\")\npak::pkg_install(\"mrcaseb/ggpath\")\n```\n\n## Examples\n\nThe two main features to provide images in a ggplot are a geom (`geom_from_path()`) and theme elements (`element_path()` \u0026 `element_raster()`). All of them replace image urls, local image paths, or raw image data with the actual image. And to improve performance, the images are cached locally.\n\nThe below examples use local image files that are shipped with the package. Let's locate the images first.\n\n```{r}\nr_logo \u003c- \"https://cran.r-project.org/Rlogo.svg\"\nlocal_background_image \u003c- system.file(\"example_bg.jpg\", package = \"ggpath\")\n```\n\n### Image Geom\n\nNow, we can make a simple plot, where we use the logo image like a point by replacing the local path with the actual image.\n\n```{r dpi=300}\nlibrary(ggplot2)\nlibrary(ggpath)\nplot_data \u003c- data.frame(x = c(-1, 1), y = 1, path = r_logo)\nggplot(plot_data, aes(x = x, y = y)) +\n  geom_from_path(aes(path = path), width = 0.2) +\n  coord_cartesian(xlim = c(-2, 2)) +\n  theme_minimal()\n```\n\n### Images in Theme Elements (element_path)\n\nWe can build on top of that by adding new axis labels, axis titles, plot title and subtitle, or a caption and using a ggpath theme element. Note the usage of transparency with the `alpha` argument, the justification with the `hjust`/`vjust` arguments, or the rotation with the `angle` argument.\n\n```{r dpi=300}\nggplot(plot_data, aes(x = x, y = r_logo)) +\n  geom_from_path(aes(path = path), width = 0.2, alpha = 0.2) +\n  coord_cartesian(xlim = c(-2, 2)) +\n  theme_minimal() +\n  labs(\n    title = r_logo,\n    subtitle = r_logo,\n    x = r_logo,\n    y = r_logo,\n    caption = r_logo\n  ) +\n  theme(\n    plot.caption = element_path(hjust = 1, size = grid::unit(4, \"lines\")),\n    axis.text.y.left = element_path(size = 1, alpha = 0.4),\n    axis.title.x = element_path(),\n    axis.title.y = element_path(vjust = 0.9),\n    plot.title = element_path(hjust = 0, size = 2, alpha = 0.5),\n    plot.subtitle = element_path(hjust = 0.9, angle = 45)\n  )\n```\n\nA popular way to personalize a plot is to include a logo in the title area. As shown above, we can replace the title or subtitle with an image but not combine it with text. So if we want a title, a subtitle and still a logo in the title area, we can use the ggplot2 tag, which is actually used to implement figure numbering.\n\n```{r dpi=300}\nggplot(plot_data, aes(x = x, y = 1)) +\n  geom_from_path(aes(path = path), width = 0.2, alpha = 0.2) +\n  coord_cartesian(xlim = c(-2, 2)) +\n  theme_minimal() +\n  labs(\n    title = \"This is a very catchy title\",\n    subtitle = \"And an informative subtitle\",\n    x = \"x axis label\",\n    y = \"y axis label\",\n    caption = \"useful caption\",\n    tag = r_logo\n  ) +\n  theme(\n    plot.tag = element_path(size = 2, vjust = 1, alpha = 0.7),\n    plot.tag.position = c(0.3,1),\n  )\n```\n\nPlease note how to place the image in the whole plot area via `plot.tag.position`. So in combination with alpha you can place a logo also behind title and subtitle.\n\n### Images in Theme Elements (element_raster)\n\nThe second theme element, `element_raster()`, allows rendering of images in the plot background. It is a replacement for `ggplot2::element_rect()`. In the following example, we plot the two logos again and now set a sample background. The sample background is a photo by Dan Cristian Pădureț on Unsplash.\n\n```{r dpi=300}\nggplot(plot_data, aes(x = x, y = y)) +\n  geom_from_path(aes(path = path), width = 0.2) +\n  coord_cartesian(xlim = c(-2, 2)) +\n  theme_dark() +\n  theme(\n    plot.background = element_raster(image_path = local_background_image),\n    panel.background = element_rect(fill = \"transparent\")\n  )\n```\n\nSome notes on the plot and the general behaviour\n\n- We remove the panel background to be able to see the plot background by setting it's `fill` parameter to \"transparent\".\n- `element_raster()` defaults to plot the image to 100% of the plot width and height (`grid::unit(1, \"npc\")`). This means that it might change the aspect ratio of the image if it doesn't equal the aspect ratio of the actual plot.\n- `element_raster()` defaults to plot the image exactly in the middle of the plot (`grid::unit(0.5, \"npc\")` combined with `just = \"centre\"`). This means you can move around the image if you set it's size bigger than the plot, e.g. with `height = grid::unit(2, \"npc\")`. See `help(\"unit\", \"grid\")` for further information.\n\n## ggpath Options\n\nThe option `\"ggpath.cache\"` can be used to configure the package cache. It can be set with\n\n```{r eval=FALSE}\noptions(ggpath.cache = \"memory\")\n# or\noptions(ggpath.cache = \"filesystem\")\n# or\noptions(ggpath.cache = \"off\")\n```\n\nThe default - `\"memory\"` - caches in the current session, while `\"filesystem\"` caches on disk which means that the cache is available after starting a fresh session. All cache options time out after 24 hours.\n\n## Comparison with Similar Image-Plotting Packages\n\nThere are various ggplot2 extensions that provide similar functionality in terms of plotting images. These include but not limited to\n\n- [ggimage](https://cran.r-project.org/package=ggimage)\n- [ggpp](https://docs.r4photobiology.info/ggpp/)\n- [ggsvg](https://coolbutuseless.github.io/package/ggsvg/)\n- [ggtext](https://wilkelab.org/ggtext/)\n\nggpath combines the strengths of all of the above by providing\n\n- functions to plot images in both the panel (with [`geom_from_path`](https://mrcaseb.github.io/ggpath/reference/geom_from_path.html)) and all other plot areas (with [`element_path` \u0026 `element_raster`](https://mrcaseb.github.io/ggpath/reference/theme_elements.html)),\n- robust image aspect ratio,\n- options for changing the color of images including a grayscale transformation,\n- options for applying transparency, and\n- improved performance through image caching.\n\nThere are some downsides compared to the above mentioned packages, e.g.\n\n- cannot combine images and text to a grob as ggtext can with [`element_markdown`](https://wilkelab.org/ggtext/reference/element_markdown.html),\n- cannot modify css parts of svgs as [ggsvg can](https://github.com/coolbutuseless/ggsvg#styling-svg-with-css-aesthetics-example-1).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/mrcaseb.github.io%2Fggpath%2F","html_url":"https://awesome.ecosyste.ms/projects/mrcaseb.github.io%2Fggpath%2F","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/mrcaseb.github.io%2Fggpath%2F/lists"}