gpt4 book ai didi

旋转整个 ggplot() 而不旋转任何文本 R

转载 作者:行者123 更新时间:2023-12-04 23:18:40 27 4
gpt4 key购买 nike

我希望旋转整个图、轴和所有内容,但保持轴标签和标题的原样,以便可以水平阅读。

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))

因此,此代码生成的图最好逆时针旋转 30 度左右,如下所示:
enter image description here

但标题仍应水平显示,而不是旋转 30 度。与轴标签相同(我将绘图放在 MS word 中并用小绿色圆圈旋转它)。有什么想法吗?甚至有可能吗?

最佳答案

这对你有用吗(下面的代码)

dd

# 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")))

关于旋转整个 ggplot() 而不旋转任何文本 R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33396168/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com