gpt4 book ai didi

r - 如何在R的ggplot2中设置 "zero"方向?

转载 作者:行者123 更新时间:2023-12-02 01:09:25 25 4
gpt4 key购买 nike

在我的代码中,读取数据来绘制极坐标图图像。但“0/360”位于顶部。如何将其旋转到右手90度?

ggplot(polar, aes(x=angle, y=distance )) + coord_polar(start=0) + geom_point() +
scale_x_continuous(breaks=seq(0, 360, by=30), expand=c(0,0), lim=c(0, 360))+
scale_area()

完整的过程和结果图形如下所述: http://keveting.blogspot.tw/2012/08/r-ggplot2-code.html

coord_polar 的文档:

start : offset from 12 o'clock in radians direction: 1, clockwise ; -1, anticlockwise

所以我尝试了

ggplot(polar, aes(x=angle, y=distance)) + 
coord_polar(***start = 90, direction = -1***) +
geom_point() + scale_x_continuous(breaks=seq(0, 360, by=30), expand=c(0,0),
lim=c(0, 360)) + scale_area()

但它仍然没有按照我想要的方式将绘图向右旋转 90 度。

最佳答案

我认为这就是您正在寻找的:

ggplot(polar, aes(x=angle, y=distance)) + 
coord_polar(start = 1.57, direction=1) + geom_point() +
scale_x_continuous(breaks=seq(0, 360, by=30), expand=c(0,0), lim=c(0, 360)) +
scale_area()

enter image description here

正如coord_polar文档的链接所述,start是以弧度(而不是度数)为单位的偏移量,并且您想要旋转它顺时针(所以direction=1)。

关于r - 如何在R的ggplot2中设置 "zero"方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12114028/

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