-
-
Save rexarski/d71456911c9510e3c8930a6ac6125141 to your computer and use it in GitHub Desktop.
Rotated ggplot2 graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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