This function maps raster and point data. 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.
PlotMap(r, p = NULL, ..., 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)
'Raster*', 'SpatialGridDataFrame', 'SpatialPixelsDataFrame', or 'CRS'. An object that can be converted to a raster layer, or a coordinate reference system (CRS).
'SpatialPointsDataFrame'. Spatial point data to be plotted.
Graphics parameters to be passed to AddPoints
.
Unused if p = NULL
.
'integer'.
Layer to extract from if r
is of class RasterStack/Brick or SpatialGridDataFrame.
integer or character.
The levels attribute to use in the Raster Attribute Table (RAT);
requires r
values of class factor.
'integer'.
Desired number of intervals to partition the range of raster values (or zlim
if specified) (optional).
'numeric'. Vector of break points used to partition the colors representing numeric raster values (optional).
'numeric'. Vector of length 2 giving the minimum and maximum values for the x-axis.
'numeric'. Vector of length 2 giving the minimum and maximum values for the y-axis.
'numeric'. Vector of length 2 giving the minimum and maximum raster values for which colors should be plotted.
'numeric'.
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.
'logical'. If true, the spatial limits will be extended to the next tick mark on the axes beyond the grid extent.
'logical'. If true, the raster value limits will be extended to the next tick mark on the color key beyond the measured range.
'logical'. If true, the spatial data range is extended.
'logical'.
If true and r
is projected, the axes tickmarks are specified in degrees, minutes, and decimal seconds (DMS).
'logical'. If true, grids or graticules are drawn in back of the raster layer using white lines and a grey background.
'RasterLayer'.
An image to drawn in back of the main raster layer r
, image colors derived from vector of gray levels.
'numeric'. Opacity of the background image from 0 to 1.
'function'. Color palette to be used to assign colors in the plot, rainbow by default.
'character'.
Vector of 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.
'numeric'.
Vector of length 2 giving the maximum width and height for the graphics device in picas, respectively.
Suggested dimensions for single-column, double-column, and sidetitle figures are
c(21, 56)
, c(43, 56)
, and c(56, 43)
, respectively.
This argument is only applicable when the file
argument is specified.
'list'.
Describes the location and values of labels in the color key.
This list may include components at
and labels
.
'character'. Position of the scale bar: "bottomleft", "topleft", "topright", or "bottomright" to denote scale location.
'character'. Position of the north arrow: "bottomleft", "topleft", "topright", or "bottomright" to denote arrow location.
'character'. Label explaining the raster cell value.
'character'. Label crediting the base map.
'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 raster::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"
).
'list'.
If specified, contour lines are drawn.
The contours are described using a list of arguments supplied to contour
.
Passed arguments include "drawlables"
, "method"
, and "col"
.
'list'.
If specified, lines are drawn.
The lines are described using a list of arguments supplied to the plot method for SpatialLines.
Passed arguments include "x"
, "col"
, and "lwd"
.
'list'.
If specified, polygons are drawn.
The polygons are described using a list of arguments supplied to the plot method for SpatialPolygons.
Passed arguments include "x"
, "col"
, "border"
, and "lwd"
.
Bitmap images require a regular grid.
'list'.
If specified, lines are drawn.
The lines are described using a list of arguments supplied to the plot method for SpatialLines.
Passed arguments include "x"
, "col"
, and "lwd"
.
'logical'. If true, a color key should be drawn.
logical. If true, the raster image is drawn.
'character'. 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.
'logical'.
If true, the graphics device driver is shut down when the function exits.
Unused if file = NULL
'logical'.
If true, a bitmap raster is used to plot r
instead of using polygons.
If UseRaster
is not specified, raster images are used when the getOption("preferRaster")
is true.
Used for the side-effect of a new plot generated. Returns a 'list' object with the following graphical parameters:
device dimensions (width, height)
, in inches.
extremes of the coordinates of the plotting region (x1, x2, y1, y2)
.
relative heights on the device (upper, lower)
for the map and color-key plots.
# NOT RUN {
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 <- raster::levels(r)[[1]]
rat$land.cover <- c("Pine", "Oak", "Meadow")
rat$code <- c(12, 25, 30)
levels(r) <- rat
PlotMap(r, att = "land.cover", col = c("grey", "orange", "purple"))
PlotMap(r, att = "code")
r <- raster::raster(system.file("external/test.grd", package="raster"))
credit <- "Label crediting the map."
explanation <- "Label explaining the raster cell value."
PlotMap(r, scale.loc = "bottomright", dms.tick = TRUE, credit = credit,
explanation = explanation)
data(meuse, package = "sp")
sp::coordinates(meuse) = ~ x + y
points(meuse)
val <- PlotMap(r, scale.loc = "topleft", dms.tick = TRUE, credit = credit,
explanation = explanation, file = "Rplots1.pdf")
print(val)
pdf(file = "Rplots2.pdf", width = val$din[1], height = val$din[2])
PlotMap(r, scale.loc = "topleft", dms.tick = TRUE, credit = credit,
explanation = explanation)
points(meuse)
dev.off()
file.remove(c("Rplots1.pdf", "Rplots2.pdf"))
graphics.off()
# }
Run the code above in your browser using DataLab