Title: | Generate Tile Maps |
---|---|
Description: | Implements an algorithm for generating maps, known as tile maps, in which each region is represented by a single tile of the same shape and size. The algorithm was first proposed in "Generating Tile Maps" by Graham McNeill and Scott Hale (2017) <doi:10.1111/cgf.13200>. Functions allow users to generate, plot, and compare square or hexagon tile maps. |
Authors: | Kaelyn Rosenberg [aut, cre] |
Maintainer: | Kaelyn Rosenberg <[email protected]> |
License: | GPL-3 |
Version: | 0.2.0 |
Built: | 2024-11-12 03:56:42 UTC |
Source: | https://github.com/kaerosen/tilemaps |
Create a tile for an island that can be added to an existing tile map layout.
create_island(tile_map, position)
create_island(tile_map, position)
tile_map |
An |
position |
Either a numeric vector of length 2 giving the coordinates for the centroid of the new tile, or a string equal to "upper left", "lower left", "upper right", or "lower right" indicating in which corner of the original tile map the new tile should be located. |
Creates a single tile of the same shape and size as the tiles in the given
tile map. This tile can be added to the layout of the given tile map to
represent an island or region that is not connected to the region
represented by the given tile map. The location of the new tile is
determined by the position
argument. Setting the position
argument equal to "upper left", "lower left", "upper right", or "lower
right" will generate a tile which is located in the specified corner of the
given tile map. Setting the position
argument to a numeric vector of
length 2 will generate a tile whose centroid is located at the coordinates
given in the vector.
Returns an object of class sfc_POLYGON
representing a single
tile of the same shape and size as the tiles in the original tile map.
library(sf) northeast <- governors[c(6,7,17,18,19,27,28,30,36,37,43),] tile_map <- generate_map(northeast$geometry, square = FALSE) tile_map <- append(tile_map, create_island(tile_map, "lower right"))
library(sf) northeast <- governors[c(6,7,17,18,19,27,28,30,36,37,43),] tile_map <- generate_map(northeast$geometry, square = FALSE) tile_map <- append(tile_map, create_island(tile_map, "lower right"))
Generate a single square or hexagon tile map.
generate_map( data, square = TRUE, flat_topped = FALSE, prop = 0, interpolate = 1, smoothness = 0, shift = c(0, 0) )
generate_map( data, square = TRUE, flat_topped = FALSE, prop = 0, interpolate = 1, smoothness = 0, shift = c(0, 0) )
data |
An object of class |
square |
logical. If |
flat_topped |
logical. If |
prop |
A proportion used in specifying the standard deviation of
the Gaussian noise added to original region centroids. The standard
deviation of the Gaussian noise is calculated as the mean distance between
a region centroid and its neighboring regions' centroids multiplied by the
value provided for the |
interpolate |
A number between 0 and 1 controlling the linear interpolation between the noisy region centroids and fully-transformed region centroids. If 0, noisy region centroids are used. If 1, fully-transformed centroids are used. |
smoothness |
numeric. Controls the bandwidth of the Gaussian kernel
used for smoothing the transformed boundary polygon. The bandwidth is
calculated as the mean distance between adjacent boundary points
multiplied by the value provided for the |
shift |
A numeric vector of length two specifying the number of grid steps to shift the candidate tile map in the x and y directions before counting the number of tile centroids that lie within the transformed boundary. |
Implements an algorithm for generating tile maps proposed in "Generating Tile Maps" (McNeill and Hale 2017). The regions of the map must be contiguous. Coordinates cannot be in terms of latitude and longitude. Instead the coordinate reference system must be an appropriate planar projection.
Returns an object of class sfc_POLYGON
, containing the tiles of
the tile map in the same order as the original regions given to the
function.
McNeill, Graham, and Scott A Hale. 2017. “Generating Tile Maps.” In Computer Graphics Forum, 36:435–45. 3. Wiley Online Library.
library(sf) northeast <- governors[c(6,7,17,18,19,27,28,30,36,37,43),] northeast$tile_map <- generate_map(northeast$geometry, square = FALSE, flat_topped = TRUE)
library(sf) northeast <- governors[c(6,7,17,18,19,27,28,30,36,37,43),] northeast$tile_map <- generate_map(northeast$geometry, square = FALSE, flat_topped = TRUE)
A dataset containing the political party affiliation of the governors of the
contiguous United States (as of May 2020), as well as an sfc
object
representing the states.
governors
governors
sf
data frame with 48 observations and 3 variables:
sfc_MULTIPOLYGON
object representing states
state abbreviations
political party affiliation of state governor
spData::us_states
(https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.html)
https://www.nga.org/governors/
Generate, plot, and compare many tile maps.
many_maps( data, labels, square = TRUE, flat_topped = FALSE, prop = c(0, 0.05), interpolate = c(0.5, 1), smoothness = c(0, 5), shift = list(c(0, 0), c(0.5, 0), c(0, 0.5)), weights = c(1, 1, 1, 1), plot = TRUE, size = 2 )
many_maps( data, labels, square = TRUE, flat_topped = FALSE, prop = c(0, 0.05), interpolate = c(0.5, 1), smoothness = c(0, 5), shift = list(c(0, 0), c(0.5, 0), c(0, 0.5)), weights = c(1, 1, 1, 1), plot = TRUE, size = 2 )
data |
An object of class |
labels |
A character vector with the labels of the regions. Labels must
be in the same order as regions given for |
square |
logical. If |
flat_topped |
logical. If |
prop |
A numeric vector of proportions used in specifying the standard
deviation of the Gaussian noise added to original region centroids. The
standard deviation of the Gaussian noise is calculated as the mean
distance between a region centroid and its neighboring regions' centroids
multiplied by the value provided for the |
interpolate |
A numeric vector of values between 0 and 1 controlling the linear interpolation between the noisy region centroids and fully-transformed region centroids. If 0, noisy region centroids are used. If 1, fully-transformed centroids are used. A different set of interpolated centroids is created for each given value. |
smoothness |
numeric vector. Controls the bandwidth of the Gaussian
kernel used for smoothing the transformed boundary polygon. The bandwidth
is calculated as the mean distance between adjacent boundary points
multiplied by the value provided for the |
shift |
A list of numeric vectors of length two specifying the number of grid steps to shift the candidate tile map in the x and y directions before counting the number of tile centroids that lie within the transformed boundary. A different final tile map is created for each given value. |
weights |
A numeric vector of length 4 specifying the weights used for calculating the total cost. The first, second, third, and fourth weights are applied to the location, adjacency, angle, and roughness costs, respectively. |
plot |
logical. If |
size |
numeric. Controls size of labels in plot. |
Generates many candidate tile maps using an algorithm proposed in
"Generating Tile Maps" (McNeill and Hale 2017). The regions of the
map must be contiguous. Coordinates cannot be in terms of latitude and
longitude. Instead the coordinate reference system must be an appropriate
planar projection. The number of maps generated is equal to the product of
the lengths of the prop
, interpolate
, smoothness
, and
shift
arguments.
Returns a data.frame
in which each row corresponds to one map
and the columns contain the generated maps, the parameters used for
creating the maps, and the costs associated with each map. The
data.frame
is ordered by the total cost.
McNeill, Graham, and Scott A Hale. 2017. “Generating Tile Maps.” In Computer Graphics Forum, 36:435–45. 3. Wiley Online Library.
library(sf) northeast <- governors[c(6,7,17,18,19,27,28,30,36,37,43),] ne_maps <- many_maps(northeast$geometry, northeast$abbreviation, prop = 0, interpolate = 1, smoothness = c(0,20), shift = list(c(0,0), c(0,0.5)))
library(sf) northeast <- governors[c(6,7,17,18,19,27,28,30,36,37,43),] ne_maps <- many_maps(northeast$geometry, northeast$abbreviation, prop = 0, interpolate = 1, smoothness = c(0,20), shift = list(c(0,0), c(0,0.5)))
Plot many maps of a single area.
plot_many_maps(map_list, labels, size = 2)
plot_many_maps(map_list, labels, size = 2)
map_list |
A list of |
labels |
A character vector containing the labels for the regions of
the |
size |
numeric. Controls size of labels in plot. |
Each element of the map_list
argument must have the same number of
features, with the first feature of each element corresponding to the same
region, the second feature of each element corresponding to the same region,
etc. Region labels must be in the same order as the regions of each
sfc_POLYGON
object.
Prints a plot with labels of the maps in the map_list
argument.
library(sf) northeast <- governors[c(6,7,17,18,19,27,28,30,36,37,43),] ne_maps <- many_maps(northeast$geometry, northeast$abbreviation, prop = 0, interpolate = 1, smoothness = c(0,20), shift = list(c(0,0), c(0,0.5)), plot = FALSE) plot_many_maps(ne_maps$map, northeast$abbreviation)
library(sf) northeast <- governors[c(6,7,17,18,19,27,28,30,36,37,43),] ne_maps <- many_maps(northeast$geometry, northeast$abbreviation, prop = 0, interpolate = 1, smoothness = c(0,20), shift = list(c(0,0), c(0,0.5)), plot = FALSE) plot_many_maps(ne_maps$map, northeast$abbreviation)