rotator {artpack} | R Documentation |
Rotate Points in a Data Frame Based on an Anchor Point
Description
Rotates the x
and y
points in a given data frame by a given angle based on a designated anchor point.
Usage
rotator(data, x, y, angle = 5, anchor = "center", drop = FALSE)
Arguments
data |
A data frame or tibble with at least |
x |
A numeric variable in |
y |
A numeric variable in |
angle |
The angle (in degrees) the points in |
anchor |
The anchor point for the rotation. Default is "center". Options include:"center", "bottom", "top", "left", and "right" |
drop |
Logical |
Value
A data frame
Examples
library(ggplot2)
original_square <- data.frame(
x = c(0, 3, 3, 0, 0),
y = c(0, 0, 3, 3, 0)
)
rotated_square <- rotator(data = original_square,
x = x,
y = y,
angle = 45,
anchor = "center")
ggplot()+
geom_path(data = original_square,
aes(x,y),
color = "red")+
geom_polygon(data = rotated_square,
aes(x,y),
fill = "purple")+
coord_equal()
[Package artpack version 0.1.0 Index]