{"id":13857584,"url":"https://github.com/statnmap/waffler","last_synced_at":"2025-04-19T17:09:59.737Z","repository":{"id":69754382,"uuid":"172268920","full_name":"statnmap/waffler","owner":"statnmap","description":"wafflerize points data","archived":false,"fork":false,"pushed_at":"2019-04-02T12:16:02.000Z","size":513,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-07T15:02:06.523Z","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/statnmap.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,"dei":null}},"created_at":"2019-02-23T22:01:55.000Z","updated_at":"2023-09-05T12:40:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"6de63c8d-98d2-44bc-9b2b-4c54b5b9975a","html_url":"https://github.com/statnmap/waffler","commit_stats":null,"previous_names":["statnmap/waffler","thinkr-open/waffler"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2Fwaffler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2Fwaffler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2Fwaffler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2Fwaffler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/statnmap","download_url":"https://codeload.github.com/statnmap/waffler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224964643,"owners_count":17399434,"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-05T03:01:41.221Z","updated_at":"2024-11-16T19:45:23.072Z","avatar_url":"https://github.com/statnmap.png","language":"R","funding_links":[],"categories":["R"],"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 setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"50%\",\n  fig.align = \"center\"\n)\n```\n# waffler\n\nThe goal of waffler is to generate the world largest waffles as interactive spatial grid.\n\n```{r}\nknitr::include_graphics(\"img/gaufre-au-caramel-beurre-sale.jpg\")\n```\n\n\u003e See the related SatRdays Paris presentation to understand the origin: \u003chttps://github.com/statnmap/prez/blob/master/2019-02-22_SatRdays_Paris.pdf\u003e\n\n## Installation\n\nYou can install the released version of waffler from github with:\n\n``` r\n# install.packages(\"remotes\")\nremotes::install_github(\"ThinkR-open/waffler\")\n```\n\n## Example\n\n### Rasters are polygons (waffles too...)\n\n**How to render interactive grid quickly?**\n\n- Build a heart polygon waffle with {sf}\n  + Create regular grid from polygon: `st_sample`\n  + Generate more or less chocolate\n  + Create polygon grid with correct `crs` to avoid deformation on leaflet\n\n```{r}\nlibrary(waffler)\nlibrary(dplyr)\nlibrary(sf)\nlibrary(leaflet)\nlibrary(leafgl)\nlibrary(ggplot2)\nlibrary(scales)\n\n# Construct heart (code from @dmarcelinobr)\nxhrt \u003c- function(t) 16 * sin(t)^3\nyhrt \u003c- function(t) 13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t)\n\n# create heart as polygon\nheart_sf \u003c- tibble(t = seq(0, 2 * pi, by = .1)) %\u003e%\n  mutate(y = yhrt(t),\n         x = xhrt(t)) %\u003e% \n  bind_rows(., head(., 1)) %\u003e% \n  select(x, y) %\u003e% \n  as.matrix() %\u003e% \n  list() %\u003e% st_polygon() %\u003e% \n  st_sfc(crs = 2154)\n\ng1 \u003c- ggplot(heart_sf) +\n  geom_sf(fill = \"#cb181d\") +\n  coord_sf(crs = 2154, datum = 2154) +\n  ggtitle(\"Heart sf polygon\")\n  \n# create grid\nheart_grid \u003c- st_sample(heart_sf, size = 500, type = \"regular\") %\u003e% \n  cbind(as.data.frame(st_coordinates(.))) %\u003e% \n  rename(x = X, y = Y) %\u003e% \n  st_sf() %\u003e% \n  mutate(z = cos(2*x) - cos(x) + sin(y),\n         z_text = as.character(round(z)))\n    \ng2 \u003c- ggplot(heart_grid) +\n  geom_sf(colour = \"#cb181d\") +\n  coord_sf(crs = 2154, datum = 2154) +\n  ggtitle(\"Heart as regular point grid\")\n\ng3 \u003c- ggplot(heart_grid) +\n  geom_sf(aes(colour = z), size = 2) +\n  scale_colour_distiller(palette = \"YlOrBr\", type = \"seq\", direction = 1) +\n  theme(panel.background = element_rect(fill = \"#000000\")) +\n  coord_sf(crs = 2154, datum = 2154) +\n  guides(colour = FALSE) +\n  ggtitle(\"Chocolate quantity for each point\")\n```\n\n- Generate a grid polygon from points with `wafflerize`\n\n```{r, out.width = \"100%\", fig.width=14, fig.height=5}\nheart_polygon \u003c- wafflerize(heart_grid, fact = 1000)\n\ng4 \u003c- ggplot(heart_polygon) +\n  geom_sf(aes(fill = z), colour = NA) +\n  scale_fill_distiller(palette = \"YlOrBr\", type = \"seq\", direction = 1) +\n  theme(panel.background = element_rect(fill = \"#000000\")) +\n  coord_sf(crs = 4326, datum = 4326) +\n  guides(fill = FALSE) +\n  ggtitle(\"Chocolate quantity in each cell\")\n\ncowplot::plot_grid(g1, g2, g3, g4, ncol = 4)\n\n```\n\n- Quick print with {leafgl} (*prev. {leaflet.glify}*): `addGlPolygons`\n  \n```{r}\n# Define colors for `addGlPolygons`\ncols \u003c- brewer_pal(palette = \"YlOrBr\", type = \"seq\")(7)\ncolours \u003c- gradient_n_pal(cols)(rescale(heart_polygon$z))\ncolours_rgb \u003c- (t(col2rgb(colours, alpha = FALSE))/255) %\u003e% as.data.frame()\n\n# Render as leaflet\nm \u003c- leaflet() %\u003e%\n  addGlPolygons(data = heart_polygon,\n                color = colours_rgb,\n                popup = \"z_text\",\n                opacity = 1) %\u003e%\n  setView(lng = mean(st_bbox(heart_polygon)[c(1,3)]),\n          lat = mean(st_bbox(heart_polygon)[c(2,4)]), zoom = 10)\n\n# m\n```\n\n*High resolution leaflet polygons*\n```{r satrday-paris-27}\nknitr::include_graphics(\"img/leaflet_heart_big.png\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatnmap%2Fwaffler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatnmap%2Fwaffler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatnmap%2Fwaffler/lists"}