ggplot2:如何以特定角度旋转图形? [英] ggplot2: How to rotate a graph in a specific angle?

查看:851
本文介绍了ggplot2:如何以特定角度旋转图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将ggplot2图旋转一个自己指定的角度.我发现了如何使用element_text(angle = 20) 旋转坐标轴文本 .我想对整个情节做些类似的事情.

I would like to rotate a ggplot2 graph by a self-specified angle. I found how to rotate the axis text with element_text(angle = 20). I would like to do something similar with the whole plot.

可复制的示例:

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:

Here's a rough idea, calling your plot p:

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

您可能想根据自己想要的角度和纵横比来定制widthheight.

You'll probably want to tailor the width and height to the angle and aspect ratio you want.

这篇关于ggplot2:如何以特定角度旋转图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆