{"id":13400693,"url":"https://github.com/clauswilke/ggtextures","last_synced_at":"2025-08-14T21:06:00.449Z","repository":{"id":56390262,"uuid":"150365021","full_name":"clauswilke/ggtextures","owner":"clauswilke","description":"Drawing textured rectangles and bars with ggplot","archived":false,"fork":false,"pushed_at":"2020-11-10T17:32:21.000Z","size":2525,"stargazers_count":158,"open_issues_count":2,"forks_count":11,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-08-04T02:39:01.831Z","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":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clauswilke.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}},"created_at":"2018-09-26T03:45:17.000Z","updated_at":"2025-03-23T17:26:55.000Z","dependencies_parsed_at":"2022-08-15T17:50:35.783Z","dependency_job_id":null,"html_url":"https://github.com/clauswilke/ggtextures","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/clauswilke/ggtextures","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clauswilke%2Fggtextures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clauswilke%2Fggtextures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clauswilke%2Fggtextures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clauswilke%2Fggtextures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clauswilke","download_url":"https://codeload.github.com/clauswilke/ggtextures/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clauswilke%2Fggtextures/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270482318,"owners_count":24591340,"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-08-14T02:00:10.309Z","response_time":75,"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":"2024-07-30T19:00:54.701Z","updated_at":"2025-08-14T21:06:00.430Z","avatar_url":"https://github.com/clauswilke.png","language":"R","funding_links":[],"categories":["Themes and aesthetics","R","Drawing \u0026 Rendering"],"sub_categories":["Miscellaneous"],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, 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# ggtextures\n\nWritten by Claus O. Wilke\n\nThis package provides functions to draw textured rectangles and bars with the grid graphics system and with ggplot2.\n\n**Note: The package is at the stage of tech demo/proof of concept. It is not ready for production purposes.**\n\n## Installation\n\nPlease install from github via:\n``` r\ndevtools::install_github(\"clauswilke/ggtextures\")\n```\n\n## Example\n\nBasic example of a textured rectangle drawn with grid:\n```{r texture-grob}\nlibrary(ggtextures)\nlibrary(grid)\nlibrary(magick)\n\nimg \u003c- image_read(\"https://jeroen.github.io/images/Rlogo.png\")\n\ngrid.newpage()\ntg1 \u003c- texture_grob(\n  img,\n  x = unit(.2, \"npc\"), y = unit(.05, \"npc\"),\n  width = unit(.1, \"npc\"), height = unit(.9, \"npc\"),\n  img_width = unit(.5, \"in\"), ncol = 1\n)\ntg2 \u003c- texture_grob(\n  img,\n  x = unit(.5, \"npc\"), y = unit(.05, \"npc\"),\n  width = unit(.3, \"npc\"), height = unit(.6, \"npc\"),\n  img_width = unit(.5, \"in\"), ncol = 1\n)\n\ngrid.draw(tg1)\ngrid.draw(tg2)\n```\n\nThis is a basic example of textured rectangles in ggplot2:\n```{r geom-textured-rect}\nlibrary(ggplot2)\nlibrary(tibble)\n\ndata \u003c- tibble(\n  xmin = c(1, 2.5), ymin = c(1, 1), xmax = c(2, 4), ymax = c(4, 3),\n  image = list(\n    \"https://jeroen.github.io/images/Rlogo.png\",\n    image_read_svg(\"https://jeroen.github.io/images/tiger.svg\")\n  )\n)\n\nggplot(data, aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax, image = image)) +\n  geom_textured_rect(img_width = unit(1, \"in\"))\n```\nNote that we are reading in the svg file explicitly, using the function `image_read_svg()` from the magick package. This is needed for proper handling of transparencies in svg files.\n\n\nWe can also make a textured equivalent to `geom_col()` or `geom_bar()`:\n```{r geom-textured-col}\ndf \u003c- tibble(\n  trt = c(\"a\", \"b\", \"c\"),\n  outcome = c(2.3, 1.9, 3.2),\n  image = c(\n    \"http://www.hypergridbusiness.com/wp-content/uploads/2012/12/rocks2-256.jpg\",\n    \"http://www.hypergridbusiness.com/wp-content/uploads/2012/12/stone2-256.jpg\",\n    \"http://www.hypergridbusiness.com/wp-content/uploads/2012/12/siding1-256.jpg\"\n  )\n)\n\nggplot(df, aes(trt, outcome, image = image)) +\n  geom_textured_col(img_width = unit(0.5, \"null\"))\n\nimages = c(\n  compact = \"http://www.hypergridbusiness.com/wp-content/uploads/2012/12/rocks2-256.jpg\",\n  midsize = \"http://www.hypergridbusiness.com/wp-content/uploads/2012/12/stone2-256.jpg\",\n  suv = \"http://www.hypergridbusiness.com/wp-content/uploads/2012/12/siding1-256.jpg\",\n  `2seater` = \"http://www.hypergridbusiness.com/wp-content/uploads/2012/12/mulch1-256.jpg\",\n  minivan = \"http://www.hypergridbusiness.com/wp-content/uploads/2012/12/rocks1-256.jpg\",\n  pickup = \"http://www.hypergridbusiness.com/wp-content/uploads/2012/12/wood3-256.jpg\",\n  subcompact = \"http://www.hypergridbusiness.com/wp-content/uploads/2012/12/concrete1-256.jpg\"\n)\n\nggplot(mpg, aes(class, image = class)) +\n  geom_textured_bar() +\n  scale_image_manual(values = images)\n\nggplot(mpg, aes(factor(trans), image = class)) +\n  geom_textured_bar() +\n  scale_image_manual(values = images)\n```\n\nIsotype bars can be drawn with `geom_isotype_bar()` and `geom_isotype_col()`. The units of the images are set as grid native units. Default is that the image height corresponds to one data unit.\n```{r geom-isotype-col}\ndata \u003c- tibble(\n  count = c(5, 3, 6),\n  animal = c(\"giraffe\", \"elephant\", \"horse\"),\n  image = list(\n    image_read_svg(\"http://steveharoz.com/research/isotype/icons/giraffe.svg\"),\n    image_read_svg(\"http://steveharoz.com/research/isotype/icons/elephant.svg\"),\n    image_read_svg(\"http://steveharoz.com/research/isotype/icons/horse.svg\")\n  )\n)\n\nggplot(data, aes(animal, count, image = image)) +\n  geom_isotype_col() +\n  theme_minimal()\n\nggplot(data, aes(animal, count, image = image)) +\n  geom_isotype_col(\n    img_width = grid::unit(1, \"native\"), img_height = NULL,\n    ncol = NA, nrow = 1, hjust = 0, vjust = 0.5, fill = \"#80808040\"\n  ) +\n  coord_flip() +\n  theme_minimal()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclauswilke%2Fggtextures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclauswilke%2Fggtextures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclauswilke%2Fggtextures/lists"}