{"id":13858306,"url":"https://github.com/EmilHvitfeldt/tilemapr","last_synced_at":"2025-07-13T23:31:57.067Z","repository":{"id":93529156,"uuid":"91603168","full_name":"EmilHvitfeldt/tilemapr","owner":"EmilHvitfeldt","description":"R functions for square and hextile maps","archived":false,"fork":false,"pushed_at":"2017-12-22T17:39:21.000Z","size":1721,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T22:12:25.495Z","etag":null,"topics":["data-visualization","ggplot2","hextile-maps","r","rstats"],"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/EmilHvitfeldt.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":"2017-05-17T17:32:20.000Z","updated_at":"2023-08-17T22:51:17.000Z","dependencies_parsed_at":"2023-04-12T05:34:01.460Z","dependency_job_id":null,"html_url":"https://github.com/EmilHvitfeldt/tilemapr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/EmilHvitfeldt/tilemapr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmilHvitfeldt%2Ftilemapr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmilHvitfeldt%2Ftilemapr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmilHvitfeldt%2Ftilemapr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmilHvitfeldt%2Ftilemapr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EmilHvitfeldt","download_url":"https://codeload.github.com/EmilHvitfeldt/tilemapr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmilHvitfeldt%2Ftilemapr/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265220704,"owners_count":23729867,"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":["data-visualization","ggplot2","hextile-maps","r","rstats"],"created_at":"2024-08-05T03:02:03.569Z","updated_at":"2025-07-13T23:31:52.058Z","avatar_url":"https://github.com/EmilHvitfeldt.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, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\"\n)\n```\n\n## Overview\n\n[![Travis build status](https://travis-ci.org/EmilHvitfeldt/tilemapr.svg?branch=master)](https://travis-ci.org/EmilHvitfeldt/tilemapr)\n\nR functions for creating square and hextile maps for various countries (only USA for now). \n\n## Installation\n\n```{r, eval = FALSE}\n# install.packages(\"devtools\")\ndevtools::install_github(\"EmilHvitfeldt/tilemapr\", force = TRUE)\n```\n\n## Usage\n\n```{r, include=FALSE}\ndevtools::install_github(\"EmilHvitfeldt/tilemapr\", force = TRUE)\n```\n\n\nTile grid maps are good alternative when the population isn't of much interest. Below we see a minimal example using ggplot2 and `geom_map()`:\n\n```{r, message=FALSE}\nlibrary(tidyverse)\nlibrary(tilemapr)\n\n# Creating data\ncrimes \u003c- data.frame(state = tolower(rownames(USArrests)), USArrests)\nstates_map \u003c- square_usa()\n\nggplot(crimes, aes(map_id = state)) +\n  geom_map(aes(fill = Murder), map = states_map) +\n  expand_limits(x = states_map$long, y = states_map$lat)\n```\n\nAll the functions include a number of parameters to control the resulting data.frame. The two most important ones are the `d` and `center`. `d` is a kind of diameter parameter which is used to control the size of the tiles. And `center` make the function gives us a data.frame with the coordinates of the center of the tile.\n\n```{r}\nstates_map \u003c- hex_usa(d = 0.5)\n\nggplot(crimes, aes(map_id = state)) +\n  geom_map(aes(fill = Murder), map = states_map) +\n  expand_limits(x = states_map$long, y = states_map$lat) +\n  geom_text(data = hex_usa(d = 0.5, center = TRUE), \n            aes(x = long, y = lat, label = region_abr), \n            inherit.aes = FALSE)\n```\n\nWe see here that DC is floating, this will be a common issue. It can be resolved by either removing it with `exclude` or to plotting a dataless map underneath:\n\n```{r}\nstates_map \u003c- hex_usa(d = 0.5)\n\nggplot(states_map, aes(map_id = region)) +\n  geom_map(aes(), map = states_map) +\n  geom_map(data = crimes, map = states_map,\n           aes(fill = Murder, map_id = state)) +\n  expand_limits(x = states_map$long, y = states_map$lat) +\n  geom_text(data = hex_usa(d = 0.5, center = TRUE), \n            aes(x = long, y = lat, label = region_abr), \n            inherit.aes = FALSE)\n```\n\nLastly some of the functions have different layout, which are picked using the `style`.\n\n```{r, echo=FALSE, message=FALSE}\nlibrary(gridExtra)\n\nstates_map \u003c- square_usa(style = \"The Guardian\")\n\nq1 \u003c- ggplot(crimes, aes(map_id = state)) +\n  geom_map(aes(fill = Murder), map = square_usa(style = \"NPR\")) +\n  expand_limits(x = c(-1, 13), y = c(-2, 9)) +\n  labs(title = \"NPR\") + \n  guides(fill = \"none\") +\n  theme_void() + \n  coord_fixed(ratio = 1)\nq2 \u003c- ggplot(crimes, aes(map_id = state)) +\n  geom_map(aes(fill = Murder), map = square_usa(style = \"The New York Times\")) +\n  expand_limits(x = c(-1, 13), y = c(-2, 9)) +\n  labs(title = \"The New York Times\") + \n  guides(fill = \"none\") +\n  theme_void() + \n  coord_fixed(ratio = 1)\nq3 \u003c- ggplot(crimes, aes(map_id = state)) +\n  geom_map(aes(fill = Murder), map = square_usa(style = \"538\")) +\n  expand_limits(x = c(-1, 13), y = c(-2, 9)) +\n  labs(title = \"538\") + \n  guides(fill = \"none\") +\n  theme_void() + \n  coord_fixed(ratio = 1)\nq4 \u003c- ggplot(crimes, aes(map_id = state)) +\n  geom_map(aes(fill = Murder), map = square_usa(style = \"Propublica\")) +\n  expand_limits(x = c(-1, 13), y = c(-2, 9)) +\n  labs(title = \"Propublica\") + \n  guides(fill = \"none\") +\n  theme_void() + \n  coord_fixed(ratio = 1)\nq5 \u003c- ggplot(crimes, aes(map_id = state)) +\n  geom_map(aes(fill = Murder), map = square_usa(style = \"Bloomberg\")) +\n  expand_limits(x = c(-1, 13), y = c(-2, 9)) +\n  labs(title = \"Bloomberg\") + \n  guides(fill = \"none\") +\n  theme_void() + \n  coord_fixed(ratio = 1)\nq6 \u003c- ggplot(crimes, aes(map_id = state)) +\n  geom_map(aes(fill = Murder), map = square_usa(style = \"The Guardian\")) +\n  expand_limits(x = c(-1, 13), y = c(-2, 9)) +\n  labs(title = \"The Guardian\") + \n  guides(fill = \"none\") +\n  theme_void() + \n  coord_fixed(ratio = 1)\nq7 \u003c- ggplot(crimes, aes(map_id = state)) +\n  geom_map(aes(fill = Murder), map = square_usa(style = \"Wall Street Journal\")) +\n  expand_limits(x = c(-1, 13), y = c(-2, 9)) +\n  labs(title = \"Wall Street Journal\") + \n  guides(fill = \"none\") +\n  theme_void() + \n  coord_fixed(ratio = 1)\nq8 \u003c- ggplot(crimes, aes(map_id = state)) +\n  geom_map(aes(fill = Murder), map = square_usa(style = \"WNYC\")) +\n  expand_limits(x = c(-1, 13), y = c(-2, 9)) +\n  labs(title = \"WNYC\") + \n  guides(fill = \"none\") +\n  theme_void() + \n  coord_fixed(ratio = 1)\nq9 \u003c- ggplot(crimes, aes(map_id = state)) +\n  geom_map(aes(fill = Murder), map = square_usa(style = \"The Marshall Project\")) +\n  expand_limits(x = c(-1, 13), y = c(-2, 9)) +\n  labs(title = \"The Marshall Project\") + \n  guides(fill = \"none\") +\n  theme_void() + \n  coord_fixed(ratio = 1)\n\ngrid.arrange(q1, q2, q3, q4, q5, q6, q7, q8, q9, ncol = 3, nrow = 3)\n```\n\n## References\n\nI have gotten the corrent layouts from [http://blog.yanofsky.info/ (square_usa)](http://blog.yanofsky.info/post/117635988235/there-appears-to-be-some-disagreement-on-the?tweet=tweet) and [http://blog.apps.npr.org/ (hex_usa)](http://blog.apps.npr.org/2015/05/11/hex-tile-maps.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEmilHvitfeldt%2Ftilemapr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEmilHvitfeldt%2Ftilemapr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEmilHvitfeldt%2Ftilemapr/lists"}