Learn R Programming

rdwplus (version 0.1.0)

plot_GRASS: A function to plot a raster from the current GRASS mapset

Description

Given the name of a raster in the current GRASS mapset, this function will plot it as a RasterLayer object.

Usage

plot_GRASS(x, out_x, ...)

Value

Nothing.

Arguments

x

The name of an object in the current GRASS mapset.

out_x

Optional. If supplied, the function makes a call to retrieve_raster and writes out the raster to the file path out_x. Otherwise the function will write the layer to tempdir.

...

Additional arguments to plot.

Examples

Run this code
# Will only run if GRASS is running
if(check_running()){

# Load data set
dem <- system.file("extdata", "dem.tif", package = "rdwplus")
landuse <- system.file("extdata", "landuse.tif", package = "rdwplus")
sites <- system.file("extdata", "site.shp", package = "rdwplus")
stream_shp <- system.file("extdata", "streams.shp", package = "rdwplus")

# Set environment parameters and import data to GRASS
set_envir(dem)
raster_to_mapset(rasters = c(dem, landuse), as_integer = c(FALSE, TRUE))
vector_to_mapset(vectors = c(sites, stream_shp))

# Rasterise streams and sites
rasterise_stream("streams", "streams_rast.tif", overwrite = TRUE)
point_to_raster(outlets = "site", out = "sites_rast.tif", overwrite = TRUE)

# Plot
# Set number 1
par(mfrow = c(1,2))
plot_GRASS("dem.tif", col = topo.colors(15))
plot_GRASS("sites_rast.tif", col = heat.colors(1), add = TRUE)

# Set number 2
plot_GRASS("landuse.tif", col = topo.colors(2))
plot_GRASS("streams_rast.tif", col = heat.colors(1), add = TRUE)

# Reset plotting device parameters
par(mfrow = c(1, 1))
}

Run the code above in your browser using DataLab