【问题标题】:ggplot2: How to rotate a graph in a specific angle?ggplot2:如何以特定角度旋转图形?
【发布时间】:2020-04-24 05:02:50
【问题描述】:

我想将 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))

这个图应该被旋转:

【问题讨论】:

  • This answer 会做到这一点,除了剪辑之外,我确信有一种方法可以将视口嵌套在更大的视口中以获得您的结果。
  • @Gregor 谢谢,完美的解决方案!

标签: r ggplot2 graph rotation angle


【解决方案1】:

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

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

您可能希望将widthheight 调整为您想要的角度和纵横比。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 2016-02-18
    • 1970-01-01
    相关资源
    最近更新 更多