knitr::opts_chunk$set( collapse=TRUE, fig.retina=2, message=FALSE, warning=FALSE, fig.path = "man/figures/README-" ) options(width=120)
A ggplot2 Geom for World Tile Grids
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'.
The following functions are implemented:
hrbrpkghelpr::describe_ingredients()
The following data is included/exported:
wtg
: World Tile Grid Basemap Data
hrbrpkghelpr::install_block()
library(worldtilegrid) library(tidyverse) # current verison packageVersion("worldtilegrid")
iso3cs <- worldtilegrid::wtg$alpha.3 set.seed(1) data_frame( ctry = iso3cs, `Thing Val` = sample(1000, length(ctry)) ) -> xdf ggplot(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()
set.seed(1) data_frame( ctry = worldtilegrid::wtg$alpha.3[1:30], `Thing Val` = sample(1000, length(ctry)) ) -> xdf ggplot(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()
set.seed(1) data_frame( ctry = worldtilegrid::wtg$alpha.3, `Thing Val` = sample(1000, length(ctry)), grp = 'Thing One' ) -> xdf1 data_frame( ctry = worldtilegrid::wtg$alpha.3, `Thing Val` = sample(1000, length(ctry)), grp = 'Thing Two' ) -> xdf2 bind_rows( xdf1, xdf2 ) -> xdf ggplot(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()
The geom will fill in the gaps for you:
set.seed(1) tibble( ctry = sample(iso3cs, 40), `Thing Val` = sample(1000, length(ctry)), grp = 'Thing One' ) -> xdf1 tibble( ctry = sample(iso3cs, 40), `Thing Val` = sample(1000, length(ctry)), grp = 'Thing Two' ) -> xdf2 bind_rows( xdf1, xdf2 ) -> xdf ggplot(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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.