scale_polygon: Scale polygons around their center

Description Usage Arguments Value Examples

View source: R/polygon_operations.R

Description

Scale polygons around their center

Usage

1
scale_polygon(poly, scaling)

Arguments

poly

a data frame defining a polygon (x and y coordinates)

scaling

a numeric vector that defines the scaling factor

Value

data.frame defining a scaled polygon

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
scale_polygon(data.frame(x = c(1, 2, 3), y = c(1, 2, 1)), 2)

poly <- data.frame(x = c(1, 1, 0, 0), y = c(1, 0, 0, 1))
library(ggplot2)
ggplot(data = NULL, aes(x = x, y = y)) +
  geom_polygon(data = poly, fill = "black") +
  geom_polygon(data = scale_polygon(poly, 0.5), fill = "gray") +
  geom_polygon(data = scale_polygon(poly, 2), alpha = 0.2, fill = "red") +
  geom_polygon(data = scale_polygon(poly, c(1, 3)), alpha = 0.2, fill = "green") +
  geom_polygon(data = scale_polygon(poly, c(3, 1)), alpha = 0.2, fill = "blue")

jspaezp/flowhelperrr documentation built on Jan. 1, 2021, 7:10 a.m.