{"id":20667874,"url":"https://github.com/statnmap/hatchedpolygons","last_synced_at":"2026-02-18T03:35:24.462Z","repository":{"id":117562917,"uuid":"90766217","full_name":"statnmap/HatchedPolygons","owner":"statnmap","description":"Create a hatched area for SpatialPolygons in R","archived":false,"fork":false,"pushed_at":"2024-05-13T14:45:52.000Z","size":5633,"stargazers_count":13,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-25T14:25:34.890Z","etag":null,"topics":["hatched-areas","rspatial"],"latest_commit_sha":null,"homepage":"https://statnmap.github.io/HatchedPolygons/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/statnmap.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2017-05-09T16:09:57.000Z","updated_at":"2025-08-28T04:06:39.000Z","dependencies_parsed_at":"2025-01-17T13:19:08.236Z","dependency_job_id":"8dd15379-d399-436a-a602-b21b4507a2ee","html_url":"https://github.com/statnmap/HatchedPolygons","commit_stats":{"total_commits":21,"total_committers":3,"mean_commits":7.0,"dds":0.2857142857142857,"last_synced_commit":"1ed7c322bdb7cb1638c131e885bd1d7e439ac6a4"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/statnmap/HatchedPolygons","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2FHatchedPolygons","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2FHatchedPolygons/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2FHatchedPolygons/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2FHatchedPolygons/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/statnmap","download_url":"https://codeload.github.com/statnmap/HatchedPolygons/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2FHatchedPolygons/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29567542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T00:47:08.760Z","status":"online","status_checked_at":"2026-02-18T02:00:09.468Z","response_time":162,"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":["hatched-areas","rspatial"],"created_at":"2024-11-16T19:45:25.524Z","updated_at":"2026-02-18T03:35:19.449Z","avatar_url":"https://github.com/statnmap.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\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# Copy reference/images to man/images\n# reference folder is required to work with pkgdown\nif (!dir.exists(\"man/figures\")) {\n  dir.create(\"man/figures\")\n}\nfile.copy(list.files(\"reference/figures\", full.names = TRUE),\n  \"man/figures\",\n  overwrite = TRUE\n)\n```\n\n# HatchedPolygons\n\n\u003c!-- badges: start --\u003e\n[![DOI](https://zenodo.org/badge/90766217.svg)](https://zenodo.org/badge/latestdoi/90766217)\n[![R-CMD-check](https://github.com/statnmap/HatchedPolygons/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/statnmap/HatchedPolygons/actions/workflows/R-CMD-check.yaml)\n\u003c!-- badges: end --\u003e\n\n\nThis R package creates a area filled by SpatialLines to allow for hatched areas in SpatialPolygons.  \nThis may be particularly useful when SpatialPolygons show holes but also for drawing hatched areas in leaflet Polygons.\n\nTo install it:\n```\ndevtools::install_github(\"statnmap/HatchedPolygons\")\n```\n\n## Create a hatched area for SpatialPolygons in R\n\n### With {sp}\n```{r, message=FALSE}\nlibrary(sp)\nlibrary(sf)\nlibrary(HatchedPolygons)\nlibrary(ggplot2)\n\n# Create two polygons: second would be a hole inside the first\nxy \u003c- cbind(\n  x = c(13.4, 13.4, 13.6, 13.6, 13.4),\n  y = c(48.9, 49, 49, 48.9, 48.9)\n)\nhole.xy \u003c- cbind(\n  x = c(13.5, 13.5, 13.45, 13.45, 13.5),\n  y = c(48.98, 48.92, 48.92, 48.98, 48.98)\n)\n\n# Create SpatialPolygon\nxy.sp \u003c- SpatialPolygonsDataFrame(\n  SpatialPolygons(list(\n    Polygons(list(\n      Polygon(xy),\n      Polygon(hole.xy, hole = TRUE)\n    ), \"1\"),\n    Polygons(list(\n      Polygon(hole.xy + 0.2, hole = TRUE),\n      Polygon(xy + 0.2),\n      Polygon(xy + 0.35)\n    ), \"2\")\n  )),\n  data = data.frame(id = as.character(c(1, 2)))\n)\n\n# Allows for different hatch densities and directions for each polygon\nxy.sp.hatch \u003c- hatched.SpatialPolygons(xy.sp, density = c(40, 60), angle = c(45, 135))\n\n# Draw again polygons with holes\npar(bg = \"lightblue\", mar = c(2, 2, 0.5, 0.5))\nplot(xy.sp, col = c(\"blue\", \"red\"))\nplot(xy.sp.hatch,\n  col = c(\"cyan\", \"grey90\")[as.numeric(xy.sp.hatch$ID)],\n  lwd = 3, add = TRUE\n)\n```\n\n### With {sf}\n\n_Note that the current implementation transforms sf object as sp, then back to sf_\n\n```{r}\n# Also with {sf}\nxy.sf \u003c- sf::st_as_sf(xy.sp) # simulate st_read()\nxy.sf.hatch \u003c- hatched.SpatialPolygons(xy.sf, density = c(40, 60), angle = c(45, 135))\n\n# Plot with ggplot2\nggplot(xy.sf) +\n  geom_sf(aes(colour = id),\n    fill = \"transparent\", size = 1.5\n  ) +\n  geom_sf(\n    data = xy.sf.hatch,\n    aes(colour = ID),\n    size = 1\n  ) +\n  guides(col = FALSE)\n```\n\n\nSee documentation on the pkgdown website for details : https://statnmap.github.io/HatchedPolygons/\n\n![Hatched Polygons with Leaflet](reference/figures/Leaflet_Snapshot.jpg)\n\n_Description of this function can be found on [statnmap.com](https://statnmap.com/2017-05-23-how-to-fill-a-hatched-area-polygon-with-holes-in-leaflet-with-r)_  \n_More on my website: [Freelance - Courses and consulting in modeling with R](https://statnmap.com/)_\n\nThere is also a vignette:\n```\nvignette(\"leaflet_shading_polygon\", package = \"HatchedPolygons\")\n```\n\nCitation:   \nSébastien Rochette. (2017, August 18). Hatched area in polygons with R - v0.1.0. Zenodo. \u003chttp://doi.org/10.5281/zenodo.845493\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatnmap%2Fhatchedpolygons","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatnmap%2Fhatchedpolygons","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatnmap%2Fhatchedpolygons/lists"}