Package 'geoheatmap'

Title: Create Geospatial Cartogram Heatmaps
Description: The functionality provided by this package is an expansion of the code of the 'statebins' package, created by B. Rudis (2022), <doi:10.32614/CRAN.package.statebins>. It allows for the creation of square choropleths for the entire world, provided an appropriate specified grid is supplied.
Authors: Sanne J.W. Willems [cre, aut], Maria Rados [aut], Juan Claramunt Gonzalez [ctb]
Maintainer: Sanne J.W. Willems <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2024-11-06 05:29:47 UTC
Source: https://github.com/sjwwillems/geoheatmap

Help Index


Create a new ggplot-based geographical heatmap for a user-specified geographical grid

Description

Pass in desired data frame and grid and get back a square choropleth. The function takes inspiration from the statebins function, modifying it to allow for non-US grids and territories, e.g. as defined in the geofacet package. The output is a ggplot2 object to which additional layers can be added.

Usage

geoheatmap(
  facet_data = NULL,
  grid_data = NULL,
  facet_col = NULL,
  value_col = NULL,
  merge_col = NULL,
  dark_label = "black",
  light_label = "white",
  na_label = "white",
  font_size = 3,
  facet_border_col = "white",
  facet_border_size = 2,
  round = FALSE,
  radius = grid::unit(6, "pt"),
  ggplot2_scale_function = ggplot2::scale_fill_continuous,
  hover = FALSE,
  ...
)

Arguments

facet_data

data frame of facets (geographical locations) and values to plot

grid_data

data frame of matching geographical grid positions

facet_col

column name in facet_data that holds the facets. No duplicates; can be full names (e.g. "Netherlands") or abbreviations (e.g. "NL")

value_col

column name in facet_data that holds the values to be plotted

merge_col

grids can sometimes hold both native and anglophone language geographical names (e.g. "Bayern/Bavaria". If native option is preferable, use merge_col; defaults to "name".

dark_label, light_label, na_label

dark/light/NA label colors. The specified color will be used when the algorithm determines labels should be inverted.

font_size

font size (default = 3)

facet_border_col

default "white" - this creates the "spaces" between boxes

facet_border_size

border size

round

rounded corners (default: FALSE)

radius

if round is TRUE then use grid::unit to specify the corner radius. Default is grid::unit(6, "pt") if using rounded corners.

ggplot2_scale_function

ggplot2 scale function to use. Defaults to scale_fill_continuous

hover

if hover is TRUE, enables interactive plotly plot (see also ggplotly). Note it only works when round is set to FALSE.

...

additional parameters to the scale function

Details

Like in the statebins package, we offer the option to specify a dark_label color and a light_label color. Depending on the selected colour scale function, geoheatmap will use that information to determine what label to use on lighter/darker tiles. This should in principle mean that labels never fade into the background. Note that this only applies if colours are defined within function, i.e. not called after the object has already been created.

You can customize the scale function you pass in by using name parameters. All named parameters not used by geoheatmap() itself get passed to the scale function.

The default theme is set to theme_void(), but this can be either overwritten, or added onto depending on intended plot purposes.

Value

ggplot2 object

References

Bob Rudis. (2022). statebins: Create United States Uniform Cartogram Heatmaps. R package version 1.4.0. URL: https://CRAN.R-project.org/package=statebins

Ryan Hafen. (2018). geofacet: 'ggplot2' Faceting Utilities for Geographical Data. R package version 0.2.1. URL: https://CRAN.R-project.org/package=geofacet

See Also

statebins geofacet

Examples

data(internet)
library(geofacet)
library(ggplot2)

internet_2015 <- subset(internet, year == 2015)
geoheatmap(facet_data= internet_2015, grid_data= europe_countries_grid1,
                    facet_col = "country", value_col = "users")

Individuals using the Internet

Description

This dataset contains information on the percentage of individuals using the Internet within a given population, categorized by country and year. It helps to measure the digital divide and track progress internet accessibility worldwide. Internet users are defined as individuals who have used the Internet (from any location) in the last 3 months. The data is collected from national surveys and telecommunications ministries and is regularly updated (last update: 2022) to reflect the latest available figures.

Usage

internet

Format

A data frame with 7101 observations (long format) on the following 3 variables:

country

list of countries for which data was collected; there are 263 unique entries, including UN-recognized countries, dependent and autonomous territories.

year

year in which data was recorded in.

users

amount of population with active internet usage, expressed in percentage.

Details

Dataset contains a country name ("Democratic Republic of Korea") that has a encoding that does not comply with the UTF-8, so this observation is removed from the dataset to avoid encoding issues in the example.

Source

The World Bank. (2024). Internet Users (% of population) [Data file]. Retrieved from https://data.worldbank.org/indicator/IT.NET.USER.ZS

The World Bank Group. (2024). Internet Users (% of population) [Data file]. Retrieved from https://data.worldbank.org/indicator/IT.NET.USER.ZS

References

International Telecommunication Union (ITU). (2024). ITU data (World Telecommunication/ICT Indicators Database) used in World Bank compilation.