View source: R/transfromation.R
transform_by_matrix | R Documentation |
Transform 2D coordinates by a 3*3 matrix
transform_by_matrix(x, y = NULL, matrix = transform_matrix_affine("none"))
x |
a vector of coordinates at x axis or a data.frame if y is NULL |
y |
a vector of coordinates at y axis or NULL |
matrix |
a 3*3 affine transformation matrix |
a matrix of transformed coordinates
# coordinate for a unit square
us <- expand.grid(c(0,1), c(0,1))[c(1,3,4,2),]
us_tf <- transform_by_matrix(x = us, matrix = transform_matrix_affine("rotate", x = 0, y =0, theta = pi/4))
library(ggplot2)
library(magrittr)
ggplot() +
geom_polygon(mapping = aes(x = us[,1], y = us[,2]), fill = "blue", alpha = 0.3) +
geom_point(mapping = aes(x = us[,1], y = us[,2]), color = "blue", size = 3) +
geom_polygon(mapping = aes(x = us_tf[,1], y = us_tf[,2]), fill = "red", alpha = 0.3) +
geom_point(mapping = aes(x = us_tf[,1], y = us_tf[,2]), color = "red", size = 3) +
geom_segment(mapping = aes(x = us[,1], y = us[,2], xend = us_tf[,1], yend = us_tf[,2]),
color = "black", linetype = "dotted", size = 1, arrow = arrow(type = "closed", length = unit(0.03, "native"))) +
coord_fixed()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.