Learn R Programming

mlspatial (version 0.1.1)

plot_map_grid: Arrange Multiple tmap Plots in a Grid

Description

Arrange a list of tmap objects into a grid layout.

Usage

plot_map_grid(maps, ncol = 2)

Value

A tmap object representing arranged maps.

Arguments

maps

A list of tmap objects.

ncol

Number of columns in the grid (default is 2).

Examples

Run this code
# \donttest{
library(sf)
library(tmap)

# Load sample spatial data
nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)

# Add mock variables to map
nc$var1 <- runif(nrow(nc), 0, 100)
nc$var2 <- runif(nrow(nc), 10, 200)

# Create individual maps
map1 <- tm_shape(nc) + tm_fill("var1", title = "Variable 1")
map2 <- tm_shape(nc) + tm_fill("var2", title = "Variable 2")

# Arrange the maps in a grid using your function
plot_map_grid(list(map1, map2), ncol = 2)
# }

Run the code above in your browser using DataLab