MRGplot {MRG}R Documentation

Convenience function based on ggplot2 to plot multi-resolution grids with some default suggestions For full flexibility it is better to use ggplot2 directly.The function can also be used for ordinary grids

Description

Convenience function based on ggplot2 to plot multi-resolution grids with some default suggestions For full flexibility it is better to use ggplot2 directly.The function can also be used for ordinary grids

Usage

MRGplot(
  himg,
  var,
  linecolor,
  option = "D",
  lwd = 0,
  lwdb = 1,
  borders,
  name = waiver(),
  title = NULL,
  xlim,
  ylim,
  crs,
  clip = TRUE,
  transform = "identity",
  show.legend = TRUE
)

Arguments

himg

The grid resulting from a call to multiResGrid

var

Which variable to plot

linecolor

Which column or color to use for lines between grid cells. The default is not to plot lines

option

The color map option to use, see scale_color_viridis for more details

lwd

Line width for the grid cells. Default is zero, to remove or minimize (for pdf) the line width

lwdb

The line width for the border

borders

A polygon object with borders than can be drawn on top of the multi-resolution grid. The object will also be used to clip the grid if clip = TRUE.

name

Name to be used for color scale. The default is to use the name of the fill/color column. name = NULL will give no name.

title

The title of the plot

xlim

The limits for the x-axis. The default is to use the bounding box of the grid.

ylim

The limits for the y-axis. The default is to use the bounding box of the grid.

crs

The coordinate reference system (CRS) into which all data should be projected before plotting. If not specified, will use the CRS defined in the first sf layer of the plot.

clip

Logical; should the grid be clipped to the borders object (if exsisting)?

transform

Possible transformation of the color scale, typical values can be "log", "log10" or "sqrt", based on available transformations in the scales package. See for example transform_log and other transformations for more details.

show.legend

Logical; should the legend be shown or not.

Details

The function is a wrapper around ggplot, possibly calling geom_sf twice, for the grid itself and for the borders. The function uses the scale_color_viridis color scale.

Value

The function will plot the object, and also return a valid ggplot-object that can be further customized.

Examples



library(sf)
library(ggplot2)

if (require(giscoR)) {
  useBorder = TRUE 
} else {
  useBorder = FALSE
  print("You need to install giscoR for plotting borders and clipping the gridded maps")
}
# These are SYNTHETIC agricultural FSS data 
data(ifs_dk) # Census data

# Create spatial data
ifg = fssgeo(ifs_dk, locAdj = "LL")

if (useBorder) {
# Read country borders, only used for plotting
  borders = gisco_get_nuts(nuts_level = 0)
}

ress = c(1,5,10,20,40, 80, 160)*1000
# Gridding Utilized agricultural area (UAA)
ifl = gridData(ifg, "UAA",res = ress)

# Create a multi-resolution grid of UAA
himg1 = multiResGrid(ifl, vars = "UAA", ifg = ifg)

if (useBorder) {
  p1 = MRGplot(himg1, UAA, transform = "log10", borders = borders)
} else {
  p1 = MRGplot(himg1, UAA, transform = "log10")
}
p1

# Plot can be customized further (reverting to ggplot default color scale in this case)
p1 + scale_color_continuous() + scale_fill_continuous()





[Package MRG version 0.3.10 Index]