Learn R Programming

rasterly (version 0.2.0)

extract: Extract or replace parts of a rasterly object

Description

The extract function provides functionality for updating existing rasterly objects.

Usage

# S3 method for rasterly
[(x, name)

# S3 method for rasterly [(x, name, ...) <- value

Arguments

x

Object from which to extract element(s) or in which to replace element(s).

name

Character. A literal string to be extracted from x. See details for more information.

...

(missing) or NULL.

value

values to replace; typically an array-like R object of a similar class as x.

Details

Available names:

  • Aggregation: "data", "mapping", "plot_width", "plot_height", "range", "x_range", "y_range", "xlim", "ylim", "aesthetics", "reduction_func", "glyph", "max_size", "group_by_data_table", "drop_data", "variable_check"

  • Display: "background", "color", "alpha", "span", "show_raster", "layout"

Set level in .... level is numeric used for specifing level of `rasterly` object to modify; default is 1 for the parent layer (rasterly()).

Examples

Run this code
# NOT RUN {
library(rasterly)
r <- rasterly(
       data = data.frame(x = 1:1e4, y = runif(1e4), category = sample(1:4, 1e4, replace = TRUE)),
       mapping = aes(x = x, y = y)
) %>%
  rasterly_points(xlim = c(1, 5000)) %>%
  rasterly_points(
    mapping = aes(x = x, y = y, color = category),
    xlim = c(5001, 1e4)
  )
r["mapping"]
r["xlim"]

# reassign parent `rasterly()` mapping
r["mapping"] <- aes(x = x, y = y, color = category)
r["mapping"]

# reassign all mapping systems
r["mapping", level = 1:length(r)] <- aes(x = x, y = y)
r["mapping"]
# }

Run the code above in your browser using DataLab