geometry_transform: Perform a linear transformation on a geometry.

Description Usage Arguments Examples

Description

Perform a linear transformation on a geometry, using a specified point as the center.

Usage

1
geometry_transform(geom, m, x = 0, y = 0)

Arguments

geom

A geometry data frame.

m

A 2x2 transformation matrix.

x,y

The coordinates of the center to use for the transformation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# Some transformation matrices
shear <- matrix(c(1, 0, 0.75, 1), nrow = 2)
reflect_y <- matrix(c(-1, 0, 0, 1), nrow = 2)
t <- 30 * pi / 180
rotate30 <- matrix(c(cos(t), -sin(t), sin(t), cos(t)), nrow = 2)

scatter_ex %>% plot()
scatter_ex %>% plot() %>% geometry_transform(shear)
scatter_ex %>% geometry_transform(reflect_y) %>% plot()
scatter_ex %>% geometry_transform(rotate30) %>% plot()

bar_ex %>% plot()
# Convert to geometry_polygon
bar_ex2 <- bar_ex %>% unique() %>% geometry_pointificate()
bar_ex2 %>% geometry_transform(shear) %>% plot()
bar_ex2 %>% geometry_transform(reflect_y) %>% plot()
bar_ex2 %>% geometry_transform(rotate30) %>% plot()

# Rotate about (10, 1) instead of origin
bar_ex2 %>% geometry_transform(rotate30, 10, 1) %>% plot()

rstudio/gggeom documentation built on May 28, 2019, 4:35 a.m.