Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

gt_rotate

Rotate geometric objects


Description

Rotate geometric objects by a certain angle about center coordinates

Usage

gt_rotate(obj, x = NULL, y = NULL, angle = NULL, fid = NULL, update = TRUE)

Arguments

obj

[geometric object(1)]
the object to rotate.

x

[numeric(1)]
the x position(s) to rotate about.

y

[numeric(1)]
the y position(s) to rotate about.

angle

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

fid

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

update

[logical(1)]
whether or not to update the window slot of the resulting geom.

Value

geom of the rotated obj.

See Also

Other geometry tools: gt_filter(), gt_locate(), gt_pull(), gt_reflect(), gt_scale(), gt_skew(), gt_stretch(), gt_translate()

Examples

# rotate all geoms
visualise(gtGeoms$polygon, linewidth = 3)
newPoly <- gt_rotate(obj = gtGeoms$polygon, x = 0, y = 0, angle = 135,
                     update = FALSE)
visualise(geom = newPoly, linecol = "green", new = FALSE)

# rotate a single geom
visualise(gtGeoms$polygon, linewidth = 3)
newPoly <- gt_rotate(obj = gtGeoms$polygon, x = -10, y = 0, angle = -180,
                     update = FALSE, fid = 2)
visualise(geom = newPoly, linecol = "green", new = FALSE)

# rotate different geoms about different centers by different angles
visualise(gtGeoms$polygon, linewidth = 3)
newPoly <- gt_rotate(obj = gtGeoms$polygon,
                     x = c(0, -10),
                     y = c(-10, 0),
                     angle = c(75, -135),
                     update = FALSE)
visualise(geom = newPoly, linecol = "green", new = FALSE)

geometr

Generate and Modify Interoperable Geometric Shapes

v0.2.10
GPL-3
Authors
Steffen Ehrmann [aut, cre] (<https://orcid.org/0000-0002-2958-0796>), Dan Sunday [cph] (fast point-in-polygon algorithm.)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.