df <- data.frame(x = c(0, 1, 1, 0),
y = c(0, 0, 1, 1))
ggplot(df, aes(x, y)) +
geom_polygon(position = position_lineartrans(angle = 30))
# Custom transformation matrices
# Rotation
theta <- -30 * pi / 180
rot <- matrix(c(cos(theta), sin(theta), -sin(theta), cos(theta)), 2)
# Shear
shear <- matrix(c(1, 0, 1, 1), 2)
# Shear and then rotate
M <- rot %*% shear
ggplot(df, aes(x, y)) +
geom_polygon(position = position_lineartrans(M = M))
# Alternative shear and then rotate
ggplot(df, aes(x, y)) +
geom_polygon(position = position_lineartrans(shear = c(0, 1), angle = 30))
# Rotate and then shear
M <- shear %*% rot
ggplot(df, aes(x, y)) +
geom_polygon(position = position_lineartrans(M = M))
Run the code above in your browser using DataLab