ggplot2:如何以特定角度旋转图形?

ggplot2: How to rotate a graph in a specific angle?

我想按自定义角度旋转 ggplot2 图。我找到了如何 rotate the axis textelement_text(angle = 20)。我想对整个情节做一些类似的事情。

可重现的例子:

set.seed(123)

data_plot <- data.frame(x = sort(rnorm(1000)),
                        y = sort(rnorm(1000)))

ggplot(data_plot, aes(y, x)) +
    geom_line() # + theme(axis.title.x = element_text(angle = 20))

应旋转此图:

这是一个粗略的想法,称你的情节为p:

library(grid)
pushViewport(viewport(name = "rotate", angle = 20, clip = "off", width = 0.7, height = 0.7))
print(p, vp = "rotate")

您可能需要根据需要的角度和纵横比调整 widthheight