BookletMaker: Map Booklet Maker

Description Usage Arguments Value Examples

View source: R/BookletMaker.R

Description

This function uses a fishnet polygon to create a map booklet pdf based on a ggplot. The booklet contains an overview map with the original ggplot and the fishnet polygon added on top, as well as sub-maps for each tile of the fishnet polygon. This function currently works only for data in UTM projection.

Usage

1
2
BookletMaker(user_ggplot, user_fishnet, fishnet_col, user_width,
  user_height, user_pointsize, user_buffer, add_north, add_scale, out_dir)

Arguments

user_ggplot

A gg object. Input plot which will be used as a basis for the booklet.

user_fishnet

A sp object. For each tile of the fishnet polygon a submap will be created. See FishnetFunction.

fishnet_col

(optional) Colour of the fishnet polygon within the overview map

user_width

(optional) Width of the output pdf. Default is 7.

user_height

(optional) Height of the output pdf. Default is 7.

user_pointsize

(optional) The pointsize to be used. Default is 12.

user_buffer

(optional) Buffer around each tile in m. Default is 0.

add_north

(optional) TRUE or FALSE. Adds north arrow.

add_scale

(optional) TRUE or FALSE. Adds scalebar.

out_dir

A character string. The directory to which the output pdf should be written.

Value

A gg object containing the original ggplot with the fishnet polygon added on top.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
library(sp)
library(raster)
library(ggplot2)
library(ggsn)
library(geosphere)
library(RStoolbox)
library(pdftools)
library(magick)

# Load sample srtm and hillshade
my_srtm <- raster::brick(system.file(package = "SpatialDataToolbox",
                                     "extdata", "srtm_sample.tif"))
my_hill <- raster::brick(system.file(package = "SpatialDataToolbox",
                                     "extdata", "hillshade_sample.tif"))

# Use ggR to plot raster files
my_plot <- ggR(my_hill, # Add hillshade
               # maxpixels = my_hill@ncols*my_hill@nrows # Use full resolution
) +
  ggtitle("SRTM with hillshade") + # Add title
  ggR(my_srtm, geom_raster = TRUE, ggLayer = TRUE, alpha = 0.5, # Add srtm with alpha = 0.5
      # maxpixels = my_srtm@ncols*my_srtm@nrows # Use full resolution
  ) +
  scale_fill_gradientn(colours = terrain.colors(100), # Choose colors for srtm
                       name = "Elevation\nin m") + # Choose name for legend
  theme(plot.title = element_text(hjust = 0.5, face="bold", size=14), # Adjust position + font of title
        axis.text.y = element_text(angle = 90, hjust = 0.5)) + # Vertical y axis labels
  xlab("") + # Remove x lab
  ylab("") # Remove y lab

# Plot map
my_plot

# Create fishnet polygon from raster extent
my_extent <- methods::as(raster::extent(my_srtm), 'SpatialPolygons')
proj4string(my_extent) <- sp::CRS(as.character(raster::crs(my_srtm)))
my_fishnet <- FishnetFunction(my_poly = my_extent, extent_only = TRUE, diff_factor = 4)

# Execute with all parameters defined.
# In orer to have a landscape DinA4 format, multiply the width by 1.414286.
my_booklet <- BookletMaker(user_ggplot = my_plot,
                           user_fishnet = my_fishnet,
                           fishnet_col = "black",
                           user_width  = 7 * 1.414286,
                           user_height = 7,
                           user_pointsize = NULL,
                           out_dir = "./",
                           user_buffer = 0,
                           add_scale = TRUE,
                           add_north = TRUE)

MBalthasar/SpatialDataToolbox documentation built on Jan. 29, 2020, 3:15 a.m.