r - 如何剪辑 coord_polar 图

标签 r ggplot2

这个问题在这里已经有了答案:





How to show only part of the plot area of polar ggplot with facet?

(1 个回答)


3年前关闭。




我正在尝试绘制一些高程数据(通常在 -90 到 90 度之间),并且使用 coord_polar 取得了一定的成功。 .看看这段代码:

library(ggplot2)
#
r = c(2:8)*20
e = c(-4:9)*10
a = c(0:71)*5

points = expand.grid(r,e,a)
colnames(points) = c("distance", "elevation", "azimuth")
points$elevation[points$elevation <0] = points$elevation + 360

forEle = subset(points, azimuth == 0)


#ele_range = 
ggplot(forEle, aes( x=elevation, y=distance))+
geom_point()+
coord_polar(theta = "x", start = -1.5708, direction = -1)+
scale_y_continuous(breaks = c(0:16)*10, limits=c(0, 160)) +
scale_x_continuous(breaks=seq(0, 359, by=30), labels=c(expression(0^degree), expression(30^degree), expression(60^degree), expression(90^degree), expression(60^degree), expression(30^degree), expression(0^degree), expression(-30^degree), expression(-60^degree), expression(-90^degree), expression(-60^degree), expression(-30^degree)), limits=c(0, 360)) +
labs(title = "",
        x = "x",
        y = "y")+
theme(legend.position="bottom")

我的第一个困难是尝试将负角度映射到图上(我通过将 360 度添加到所有负值来做到这一点),但我想知道是否有更好的方法来做到这一点。其次,更重要的是,我想将输出从 -90 度剪辑(或限制)到 90 度,即图的右侧,但我没能做到。对这个问题的任何帮助表示赞赏。

最佳答案

我参加聚会有点晚了,但你的意思是这样的?

enter image description here

也可以用 -90 到 90 围绕整个圆圈来完成。

enter image description here

对于第一个:

scale_x_continuous(limits=c(-180,180),breaks=seq(-90, 90, 45))

对于第二个:
scale_x_continuous(limits=c(-90,90),breaks=seq(-90, 90, 45))

关于r - 如何剪辑 coord_polar 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17921961/

相关文章:

r - 当列名是年份时减去列

rdata 和 ggplot : specifying plot initial plot size?

r - 计算向量中的 NA,但开头除外

r - 排列向量子集的位置

readr::read_csv ("file.csv", col_types = rep ("c", times = 18)) 给出错误:与 STRSXP 不兼容

r - 查看 ggplot2::qplot 中绘图对象的调用

r - 在 ggplot2 中增加绘图区域周围的区域

r - 通过符号在ggplot2中设置特定的填充颜色

r - ggplot2:有没有办法将单个图覆盖到 ggplot 中的所有方面

r - ggplot2 geom_area 边缘不垂直