我希望旋转整个图、轴和所有内容,但保持轴标签和标题的原样,以便可以水平阅读它们。
library(ggplot2)
data(mtcars)
ggplot() + geom_point(data=mtcars,aes(x=mpg,y=cyl)) +
labs(title = "MPG vs Cylinders",
x = "", y = "") +
theme(plot.title = element_text(size=40),axis.text.x=element_text(size=35),axis.text.y=element_text(size=35))
So the plot that this code generated would ideally be rotated 30 degrees or so counter-clockwise like so:
但标题仍应水平显示,而不是旋转 30 度。与轴标签相同(我将绘图放入 MS Word 中并用绿色小圆圈旋转它)。有什么想法吗?有可能吗?
这对你有用吗(代码如下)
# install.packages("ggplot2", dependencies = TRUE)
library(ggplot2)
rotation <- 30
p <- ggplot() + geom_point(data=mtcars,aes(x=mpg,y=cyl)) + labs(title = "MPG vs Cylinders", 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)))
# install.packages("grid", dependencies = TRUE)
library(grid)
print(p, vp=viewport(angle=rotation, width = unit(.75, "npc"), height = unit(.75, "npc")))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)