# make transformer
library(ggforce)
trans <- linear_trans(shear(2, 0), rotate(-pi / 3))
# set up data to be plotted
square <- data.frame(x = c(0, 0, 4, 4), y = c(0, 1, 1, 0))
points <- data.frame(x = runif(100, 0, 4), y = runif(100, 0, 1))
# plot data normally
library(ggplot2)
ggplot(data = points, aes(x = x, y = y)) +
geom_polygon(data = square, fill = NA, color = "black") +
geom_point(color = "black") +
coord_cartesian(expand = FALSE) +
theme_classic()
# plot data with transformation
ggplot(data = points, aes(x = x, y = y)) +
geom_polygon(data = square, fill = NA, color = "black") +
geom_point(color = "black") +
coord_trans_xy(trans = trans, expand = FALSE) +
theme_classic()
Run the code above in your browser using DataLab