Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hrbrmstr/worldtilegrid
🔲🗺 World Tile Grid Geom for ggplot2 [WIP]
https://github.com/hrbrmstr/worldtilegrid
cartogram r rstats tile-grid world-tile-grid
Last synced: 6 days ago
JSON representation
🔲🗺 World Tile Grid Geom for ggplot2 [WIP]
- Host: GitHub
- URL: https://github.com/hrbrmstr/worldtilegrid
- Owner: hrbrmstr
- License: other
- Created: 2018-08-25T22:16:50.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-17T10:48:58.000Z (over 5 years ago)
- Last Synced: 2024-10-12T21:24:02.384Z (22 days ago)
- Topics: cartogram, r, rstats, tile-grid, world-tile-grid
- Language: R
- Size: 1.29 MB
- Stars: 44
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
---
```{r pkg-knitr-opts, include=FALSE}
knitr::opts_chunk$set(
collapse=TRUE, fig.retina=2, message=FALSE, warning=FALSE,
fig.path = "man/figures/README-"
)
options(width=120)
```[![Travis-CI Build Status](https://travis-ci.org/hrbrmstr/worldtilegrid.svg?branch=master)](https://travis-ci.org/hrbrmstr/worldtilegrid)
[![Coverage Status](https://codecov.io/gh/hrbrmstr/worldtilegrid/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/worldtilegrid)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/worldtilegrid)](https://cran.r-project.org/package=worldtilegrid)# worldtilegrid
A ggplot2 Geom for World Tile Grids
## Description
A "tile grid map" is a cartogram that uses same-sized tiles in approximate, relative positions of each other to represent a world map. The world tile grid relative position reference system used by this 'ggplot2' 'Geom/Stat' was the original work of 'Jon Schwabish' and converted to 'CSV' by 'Maarten Lambrechts'.
- Ref:
- Ref:## What's Inside The Tin
The following functions are implemented:
```{r ingredients, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::describe_ingredients()
```The following _data_ is included/exported:
`wtg`: World Tile Grid Basemap Data
## Installation
```{r install-ex, results='asis', echo = FALSE}
hrbrpkghelpr::install_block()
```## Usage
```{r message=FALSE, warning=FALSE, error=FALSE}
library(worldtilegrid)
library(tidyverse)# current verison
packageVersion("worldtilegrid")```
### Example (All countries are in the data set)
```{r message=FALSE, warning=FALSE, error=FALSE, fig.width=8, fig.height=8, fig.retina=2}
iso3cs <- worldtilegrid::wtg$alpha.3set.seed(1)
data_frame(
ctry = iso3cs,
`Thing Val` = sample(1000, length(ctry))
) -> xdfggplot(xdf, aes(country = ctry, fill = `Thing Val`)) +
geom_wtg(border_size = 0.5, border_col = "#252a32") +
geom_text(
aes(
label = stat(alpha.2),
colour = I(ifelse(`Thing Val` < 500, "white", "black"))
),
stat = "wtg", size = 2
) +
coord_equal() +
viridis::scale_fill_viridis() +
labs(title = "World Tile Grid") +
hrbrthemes::theme_ft_rc() +
theme_enhance_wtg()
```### Example (Only a few countries are in the data set)
```{r message=FALSE, warning=FALSE, error=FALSE, fig.width=8, fig.height=8, fig.retina=2}
set.seed(1)
data_frame(
ctry = worldtilegrid::wtg$alpha.3[1:30],
`Thing Val` = sample(1000, length(ctry))
) -> xdfggplot(xdf, aes(country = ctry, fill = `Thing Val`)) +
geom_wtg() +
geom_text(
aes(
label = stat(alpha.2),
colour = I(ifelse(`Thing Val` < 400, "#b2b2b2", "#2b2b2b"))
),
stat="wtg", size=2
) +
coord_equal() +
viridis::scale_fill_viridis() +
labs(title = "World Tile Grid") +
hrbrthemes::theme_ft_rc() +
theme_enhance_wtg()
```### Facet Example (All countries are in the data set)
```{r message=FALSE, warning=FALSE, error=FALSE, fig.width=10, fig.height=6, fig.retina=2}
set.seed(1)
data_frame(
ctry = worldtilegrid::wtg$alpha.3,
`Thing Val` = sample(1000, length(ctry)),
grp = 'Thing One'
) -> xdf1data_frame(
ctry = worldtilegrid::wtg$alpha.3,
`Thing Val` = sample(1000, length(ctry)),
grp = 'Thing Two'
) -> xdf2bind_rows(
xdf1,
xdf2
) -> xdfggplot(xdf, aes(country = ctry, fill = `Thing Val`)) +
geom_wtg() +
coord_equal() +
facet_wrap(~grp) +
viridis::scale_fill_viridis() +
labs(title = "World Tile Grid Facets") +
hrbrthemes::theme_ft_rc() +
theme_enhance_wtg()
```### Facet Example (Only a few countries are in the data set)
The geom will fill in the gaps for you:
```{r message=FALSE, warning=FALSE, error=FALSE, fig.width=10, fig.height=6, fig.retina=2}
set.seed(1)
tibble(
ctry = sample(iso3cs, 40),
`Thing Val` = sample(1000, length(ctry)),
grp = 'Thing One'
) -> xdf1tibble(
ctry = sample(iso3cs, 40),
`Thing Val` = sample(1000, length(ctry)),
grp = 'Thing Two'
) -> xdf2bind_rows(
xdf1,
xdf2
) -> xdfggplot(xdf, aes(country = ctry, fill = `Thing Val`)) +
geom_wtg(border_size = 0.5) +
coord_equal() +
facet_wrap(~grp) +
scale_fill_viridis_c(
na.value = alpha(hrbrthemes::ft_cols$gray, 2/5), direction = -1,
option = "magma"
) +
guides(
fill = guide_colourbar(title.position = "top", title.hjust = 0.5)
) +
labs(title = "World Tile Grid Facets") +
hrbrthemes::theme_ipsum_rc() +
theme_enhance_wtg() +
theme(legend.position = "bottom") +
theme(legend.key.width = unit(2, "lines"))
```