# R/plot_many_maps.R In tilemaps: Generate Tile Maps

#### Documented in plot_many_maps

```#' Plot Many Maps
#'
#' Plot many maps of a single area.
#'
#' Each element of the \code{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
#' \code{sfc_POLYGON} object.
#'
#' @param map_list A list of \code{sfc_POLYGON} objects, each containing
#'   regions of a map to be plotted.
#' @param labels A character vector containing the labels for the regions of
#'   the \code{sfc_POLYGON} objects.
#' @param size numeric. Controls size of labels in plot.
#'
#' @examples
#' 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)
#'
#' @return Prints a plot with labels of the maps in the \code{map_list}
#'  argument.
#'
#' @export

plot_many_maps <- function(map_list, labels, size = 2) {
polygons <- sf::st_sfc(unlist(map_list, recursive = FALSE, use.names = FALSE),
crs = sf::st_crs(map_list[]))
id <- rep(1:length(map_list), lengths(map_list))
labels <- rep(labels, length(map_list))
df <- data.frame(polygons, id, labels)
geometry <- df\$geometry
ggplot2::ggplot(df) +
ggplot2::geom_sf(ggplot2::aes(geometry = geometry)) +
ggplot2::geom_sf_text(ggplot2::aes(geometry = geometry, label = labels),
size = size,
fun.geometry = function(x) sf::st_centroid(x)) +
ggplot2::facet_wrap(~ id) +
ggplot2::theme_classic() +
ggplot2::theme(axis.title = ggplot2::element_blank(),
axis.text = ggplot2::element_blank(),
axis.ticks = ggplot2::element_blank(),
axis.line = ggplot2::element_blank())
}
```

## Try the tilemaps package in your browser

Any scripts or data that you put into this service are public.

tilemaps documentation built on July 10, 2020, 9:06 a.m.
{"ft_lang_label":"__label__en","ft_lang_prob":0.51645976,"math_prob":0.98668426,"size":2043,"snap":"2021-43-2021-49","text_gpt3_token_len":568,"char_repetition_ratio":0.13928397,"word_repetition_ratio":0.029411765,"special_character_ratio":0.31326482,"punctuation_ratio":0.22384427,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99416476,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-09T13:54:21Z\",\"WARC-Record-ID\":\"<urn:uuid:ac160ce5-fdf5-42ad-a300-1e3a979f4090>\",\"Content-Length\":\"33441\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5a3996bd-37be-43bb-980d-90d1b52af5aa>\",\"WARC-Concurrent-To\":\"<urn:uuid:b496ca5b-c6ff-4451-afa1-97888f372c1e>\",\"WARC-IP-Address\":\"51.81.83.12\",\"WARC-Target-URI\":\"https://rdrr.io/cran/tilemaps/src/R/plot_many_maps.R\",\"WARC-Payload-Digest\":\"sha1:LGGWTAFIPCYQFLHYBEUMOHGIW5MXEW3Y\",\"WARC-Block-Digest\":\"sha1:3MUYGHT2WZFDJG7BWVVHN2M7ZY5IAVXO\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964364169.99_warc_CC-MAIN-20211209122503-20211209152503-00473.warc.gz\"}"}