PlotMap: Plot Map

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/PlotMap.R

Description

Draw a map of raster data and geographical features. A key showing how the colors map to raster values is shown below the map. The width and height of the graphics region will be automagically determined in some cases.

Usage

 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
PlotMap(
  r,
  layer = 1,
  att = NULL,
  n = NULL,
  breaks = NULL,
  xlim = NULL,
  ylim = NULL,
  zlim = NULL,
  asp = NULL,
  extend.xy = FALSE,
  extend.z = FALSE,
  reg.axs = TRUE,
  dms.tick = FALSE,
  bg.lines = FALSE,
  bg.image = NULL,
  bg.image.alpha = 1,
  pal = NULL,
  col = NULL,
  max.dev.dim = c(43, 56),
  labels = NULL,
  scale.loc = NULL,
  arrow.loc = NULL,
  explanation = NULL,
  credit = NULL,
  shade = NULL,
  contour.lines = NULL,
  rivers = NULL,
  lakes = NULL,
  roads = NULL,
  draw.key = NULL,
  draw.raster = TRUE,
  file = NULL,
  close.file = TRUE,
  useRaster,
  simplify
)

Arguments

r

'Raster*', 'Spatial*', or 'CRS'. Object that can be converted to a raster layer, or coordinate reference system (CRS).

layer

'integer' count. Layer to extract from if r is of class 'RasterStack/Brick' or 'SpatialGridDataFrame'.

att

'integer' count or 'character' string. Levels attribute to use in the Raster Attribute Table (RAT); requires r values of class factor.

n

'integer' count. Desired number of intervals to partition the range of raster values (or zlim if specified) (optional).

breaks

'numeric' vector. Break points used to partition the colors representing numeric raster values (optional).

xlim

'numeric' vector of length 2. Minimum and maximum values for the x-axis.

ylim

'numeric' vector of length 2. Minimum and maximum values for the y-axis.

zlim

'numeric' vector of length 2. Minimum and maximum raster values for which colors should be plotted.

asp

'numeric' number. y/x aspect ratio for spatial axes. Defaults to 1 (one unit on the x-axis equals one unit on the y-axis) when r is projected, otherwise, a calculated value based on axes limits is used.

extend.xy

'logical' flag. If true, the spatial limits will be extended to the next tick mark on the axes beyond the grid extent.

extend.z

'logical' flag. If true, the raster value limits will be extended to the next tick mark on the color key beyond the measured range. Not used if the zlim argument is specified.

reg.axs

'logical' flag. If true, the spatial data range is extended.

dms.tick

'logical' flag. If true and r is projected, the axes tickmarks are specified in degrees, minutes, and decimal seconds (DMS).

bg.lines

'logical' flag. If true, grids or graticules are drawn in back of the raster layer using white lines and a grey background.

bg.image

'RasterLayer'. An image to be drawn in back of the main raster layer r, image colors are derived from a vector of gray levels. Raster values typically represent hill shading based on the slope and aspect of land-surface elevations, see hillShade function.

bg.image.alpha

'numeric' number. Opacity of the background image from 0 to 1.

pal

'function'. Color palette to be used to assign colors in the plot.

col

'character' vector. Colors to be used in the plot. This argument requires breaks specification for numeric values of r and overrides any palette function specification. For numeric values there should be one less color than breaks. Factors require a color for each level.

max.dev.dim

'numeric' vector of length 2, value is recycled as necessary. Maximum width and height for the graphics device in picas, respectively. Where 1 pica is equal to 1/6 of an inch, 4.2333 of a millimeter, or 12 points. Suggested dimensions for single-column, double-column, and side title figures are c(21, 56), c(43, 56), and c(56, 43), respectively. This argument is only applicable when the file argument is specified.

labels

'list'. Location and values of labels in the color key. This list may include components at and labels.

scale.loc

'character' string. Position of the scale bar in the main plot region; see GetInsetLocation function for keyword descriptions.

arrow.loc

'character' string. Position of the north arrow in the main plot region; see GetInsetLocation function for keyword descriptions.

explanation

'character' string. Label explaining the raster cell value.

credit

'character' string. Label crediting the base map.

shade

'list'. If specified, a semi-transparent shade layer is drawn on top of the raster layer. This layer is described using a list of arguments supplied to the hillShade function. Passed arguments include angle and direction. Additional arguments also may be passed that control the vertical aspect ratio (z.factor) and color opacity (alpha).

contour.lines

'list'. If specified, contour lines are drawn. The contours are described using a list of arguments supplied to the contour function. Passed arguments include drawlables, method, and col.

rivers

'list'. If specified, lines are drawn. The lines are described using a list of arguments supplied to the plot method for class 'SpatialLines'. Passed arguments include x, col, and lwd.

lakes

'list'. If specified, polygons are drawn. The polygons are described using a list of arguments supplied to the plot method for class 'SpatialPolygons'. Passed arguments include x, col, border, and lwd. Bitmap images require a regular grid.

roads

'list'. If specified, lines are drawn. The lines are described using a list of arguments supplied to the plot method for class 'SpatialLines'. Passed arguments include x, col, and lwd.

draw.key

'logical' flag. Whether a color key should be drawn.

draw.raster

'logical' flag. Whether the raster image should be drawn.

file

'character' string. Name of the output file. Specifying this argument will start a graphics device driver for producing a PDF or PNG file format—the file extension determines the format type. The width and height of the graphics region will be automagically determined and included with the function's returned values, see "Value" section for details; these device dimensions can be useful when creating similar map layouts in dynamic reports.

close.file

'logical' flag. Whether the graphics device driver should be shut down after the function exits. Unused if file = NULL

useRaster

'logical' flag. If true, a bitmap raster is used to plot r instead of using individual polygons for each raster cell. If UseRaster is not specified, raster images are used when the getOption("preferRaster") is true. Unused if simplify = TRUE.

simplify

'numeric' number. Specifying this argument will convert the raster r to spatial polygons prior to plotting, see Grid2Polygons function for details. If simplify > 0 the geometry of the spatial polygons is generalized using the Douglas-Peucker algorithm (Douglas and Peucker, 1961); and simplify is the numerical tolerance value to be used by the algorithm. See gSimplify function for additional information.

Value

A 'list' with the following graphical parameters:

din

device dimensions c(width, height), in inches.

usr

extremes of the coordinates of the plotting region c(x1, x2, y1, y2).

heights

relative heights on the device c(upper, lower) for the map and color-key plots.

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center

References

Douglas, D., and Peucker, T., 1961, Algorithms for the reduction of the number of points required to represent a digitized line or its caricature: The Canadian Cartographer, v. 10, no. 2, p. 112–122.

See Also

AddColorKey

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
51
52
53
54
55
56
57
58
59
60
61
62
63
r <- raster::raster(nrow = 10, ncol = 10, crs = NA)
r[] <- 1L
r[51:100] <- 2L
r[3:6, 1:5] <- 8L
r <- raster::ratify(r)
rat <- cbind(raster::levels(r)[[1]],
             land.cover = c("Pine", "Oak", "Meadow"))
levels(r) <- rat
PlotMap(r)

data(meuse, meuse.grid, package = "sp")
sp::coordinates(meuse.grid) <- ~x+y
sp::proj4string(meuse.grid) <- sp::CRS("+init=epsg:28992")
sp::gridded(meuse.grid) <- TRUE
meuse.grid <- raster::raster(meuse.grid, layer = "soil")
model <- gstat::gstat(id = "zinc", formula = zinc~1,
                      locations = ~x+y, data = meuse)
r <- raster::interpolate(meuse.grid, model)
r <- raster::mask(r, meuse.grid)
Pal <- function(n) GetColors(n, stops=c(0.3, 0.9))
breaks <- seq(0, 2000, by = 200)
credit <- paste("Data collected in a flood plain of the river Meuse,",
                "near the village of Stein (Netherlands),",
                "\nand iterpolated on a grid with 40m by 40m spacing",
                "using inverse distance weighting.")
PlotMap(r, breaks = breaks, pal = Pal, dms.tick = TRUE,
        bg.lines = TRUE, contour.lines = list("col" = "#1F1F1F"),
        credit = credit, draw.key = FALSE, simplify = 0)
AddScaleBar(unit = c("KILOMETER", "MILES"),
            conv.fact = c(0.001, 0.000621371),
            loc = "bottomright", inset = c(0.1, 0.05))
AddGradientLegend(breaks, Pal, at = breaks,
                  title = "Topsoil zinc\nconcentration\n(ppm)",
                  loc = "topleft", inset = c(0.05, 0.1),
                  strip.dim = c(2, 20))

m <- datasets::volcano
m <- m[nrow(m):1, ncol(m):1]
x <- seq(from = 2667405, length.out = ncol(m), by = 10)
y <- seq(from = 6478705, length.out = nrow(m), by = 10)
r <- raster::raster(m, xmn = min(x), xmx = max(x), ymn = min(y),
                    ymx = max(y), crs = "+init=epsg:27200")
bg.image <- raster::hillShade(raster::terrain(r, "slope"),
                              raster::terrain(r, "aspect"))
credit <- paste("Digitized from a topographic map by Ross Ihaka",
                "on a grid with 10-meter by 10-meter spacing.")
explanation <- "Elevation on Auckland's Maunga Whau volcano, in meters."
PlotMap(r, extend.z = TRUE, bg.image = bg.image,
        pal = GetColors(scheme = "DEM screen", alpha = 0.8),
        scale.loc = "bottomright", arrow.loc = "topright",
        explanation = explanation, credit = credit,
        contour.lines = list("col" = "#1F1F1FA6"), "useRaster" = TRUE)

out <- PlotMap(r, file = "Rplots1.pdf")
print(out)

pdf(file = "Rplots2.pdf", width = out$din[1], height = out$din[2])
PlotMap(r)
raster::contour(r, col = "white", add = TRUE)
dev.off()

file.remove(c("Rplots1.pdf", "Rplots2.pdf"))
graphics.off()

inlmisc documentation built on Jan. 25, 2022, 1:14 a.m.