Skip to content

Instantly share code, notes, and snippets.

@ivelasq
Last active January 7, 2023 03:39
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ivelasq/a4d544a2539d72cf9e4b0adbe1bc52c0 to your computer and use it in GitHub Desktop.
Save ivelasq/a4d544a2539d72cf9e4b0adbe1bc52c0 to your computer and use it in GitHub Desktop.
Rotated ggplot2 graph
# Credits to this Stack Overflow post
# https://stackoverflow.com/questions/13445753/force-ggplot2-scatter-plot-to-be-square-shaped
library(ggplot2)
library(grid)
rotation <- 45
p <-
ggplot() +
geom_point(data = mtcars, aes(x = mpg, y = hp)) +
labs(title = "MPG vs HP", x = "", y = "") +
theme(
plot.title = element_text(size = 20),
axis.text.x = element_text(size = 15),
axis.text.y = element_text(size = 15)
) +
theme(text = element_text(angle = (-1 * rotation)),
aspect.ratio = 1)
print(p, vp = viewport(
angle = rotation,
width = unit(0.75, "npc"),
height = unit(0.75, "npc")
))
ggsave("test.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment