Learn R Programming

geometr (version 0.1.1)

gs_line: Create a line geom

Description

Create a line geometry (of class geom) either by specifying anchor values or by sketching it.

Usage

gs_line(anchor = NULL, window = NULL, features = 1,
  vertices = NULL, sketch = NULL, ...)

Arguments

anchor

[geom(1)|data.frame(1)] Object to derive the geom from. It must include column names x, y and optionally a custom fid. To set further attributes, use setTable.

window

[data.frame(1)] in case the reference window deviates from the bounding box of anchor (minimum and maximum values), specify this here.

features

[integerish(1)] number of lines to create.

vertices

[integerish(.)] number of vertices per line; will be recycled if it does not have as many elements as specified in features.

sketch

[RasterLayer(1) | matrix(1)] Gridded object that serves as template to sketch line(s).

...

[various] additional arguments; see Details.

Value

An invisible geom.

Details

The arguments anchor and sketch indicate how the line is created:

  • if anchor is set, the line is created parametrically from the given objects' points,

  • if an object is set in sketch, this is used to create the geom interactively, by clicking into the plot.

Possible additional arguments are:

  • verbose = TRUE/FALSE

  • graphical parameters to gt_locate, in case points are sketched; see gpar

See Also

Other geometry shapes: gs_point, gs_polygon, gs_random

Examples

Run this code
# NOT RUN {
# 1. create a line programmatically
coords <- data.frame(x = c(40, 70, 70, 50),
                     y = c(40, 40, 60, 70))

# if no window is set, the bounding box will be set as window
(aGeom <- gs_line(anchor = coords))

# the vertices are plottet relative to the window
library(magrittr)
window <- data.frame(x = c(0, 80),
                     y = c(0, 80))
gs_line(anchor = coords, window = window) %>%
  visualise(linecol = "green")

# if a plot is already open, vertices are set relative to the plot window
visualise(geom = gs_line(anchor = coords), new = FALSE)

# when a geom is used in 'anchor', its properties are passed on
aGeom <- setWindow(x = aGeom, to = window)
gs_line(anchor = aGeom) %>%
  visualise(linecol = "deeppink")
# }
# NOT RUN {
# 2. sketch a line by clicking into a template
gs_line(sketch = gtRasters$continuous, vertices = 4) %>%
  visualise(linecol = "orange", linewidth = 5, new = FALSE)
# }

Run the code above in your browser using DataLab