Learn R Programming

geometr (version 0.2.5)

gt_rotate: Rotate geoms

Description

Rotate geoms by a certain angle about a center

Usage

gt_rotate(
  geom = NULL,
  angle = NULL,
  about = c(0, 0),
  fid = NULL,
  update = TRUE
)

Arguments

geom

[geom(.)] the object to rotate.

angle

[numeric(1)] the counter-clockwise angle by which geom shall be rotated (can be negative to rotate clockwise).

about

[numeric(2)] the point about which geom shall be rotated.

fid

[integerish(.)] if only a subset of features shall be rotated, specify that here.

update

[logical(1)] whether or not to update the window slot after rotation.

Value

Rotated geom.

See Also

Other geometry tools: gt_reflect(), gt_scale(), gt_sketch(), gt_skew(), gt_stretch(), gt_translate()

Examples

Run this code
# NOT RUN {
# the original object
coords <- data.frame(x = c(30, 60, 60, 40, 10, 40, 20),
                     y = c(40, 40, 60, 70, 10, 20, 40),
                     fid = c(1, 1, 1, 1, 2, 2, 2))
window <- data.frame(x = c(0, 80),
                     y = c(0, 80))
aGeom <- gs_polygon(anchor = coords, window = window)
visualise(geom = aGeom)

# rotate all geoms
rotatedGeom <- gt_rotate(geom = aGeom, angle = 90, about = c(40, 40))
visualise(geom = rotatedGeom)

# rotate a single geom
rotTri <- gt_rotate(geom = aGeom, angle = -180, about = c(30, 40), fid = 2)
visualise(geom = rotTri)

# rotate different geoms about different centers by different angles
rotateMore <- gt_rotate(geom = aGeom,
                        angle = list(90, -180),
                        about = list(c(40, 40), c(30, 40)))
visualise(geom = rotateMore)
# }

Run the code above in your browser using DataLab