You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用plotrix包的polar.plot绘制仅显示0°-180°的上半区极坐标图?

当然可以做到!用plotrix包的polar.plot()函数完全能实现只显示0°到180°的上半部分极坐标图,下面我给你详细的实现方案和可复现代码:

具体实现方法

1. 准备环境与数据集

先加载plotrix包,再创建可复现的示例数据:

# 加载plotrix包
library(plotrix)

# 可复现数据集:0°到180°(间隔10°)的角度,以及对应数值
angles <- seq(0, 180, by = 10)
values <- c(2, 3, 5, 7, 8, 9, 10, 11, 12, 11, 10, 9, 8, 7, 5, 3, 2, 1, 0)

2. 绘制上半部分极坐标图

核心是使用theta.lim参数限制角度范围,同时搭配其他参数优化图形样式:

polar.plot(
  values,
  polar.pos = angles,          # 绑定数值与对应角度
  theta.lim = c(0, 180),       # 关键:仅显示0°到180°的区域
  start = 0,                   # 设置0°位于右侧(符合常规极坐标习惯)
  clockwise = FALSE,           # 角度按逆时针方向递增
  main = "0°-180°上半部分极坐标图",
  radial.labels = seq(0, 12, by = 2),  # 径向刻度标签
  radial.lim = c(0, 12),       # 径向数值范围
  box.col = "black",           # 极坐标边框颜色
  grid.col = "gray",           # 网格线颜色
  line.col = "darkblue",       # 数据线颜色
  point.col = "red",           # 数据点颜色
  pch = 16                     # 数据点样式
)

3. 关键参数说明

  • theta.lim = c(0, 180):这是实现上半部分显示的核心,直接限定极坐标图的角度显示范围。
  • polar.pos = angles:确保每个数值对应到正确的0-180°角度区间。
  • 如果想让0°位于顶部(而非右侧),只需把start设为90,同时将theta.lim改为c(90, 270),同样能得到上半圆效果。

4. 处理全角度数据集

如果你的原始数据包含0-360°的全角度,只需先筛选出0-180°的部分再绘图:

# 示例全角度数据集
full_angles <- seq(0, 360, by = 10)
full_values <- c(2,3,5,7,8,9,10,11,12,11,10,9,8,7,5,3,2,1,0,1,2,3,5,7,8,9,10,11,12,11,10,9,8,7,5,3,2)

# 筛选0-180°的数据
filtered_idx <- full_angles >= 0 & full_angles <= 180
filtered_angles <- full_angles[filtered_idx]
filtered_values <- full_values[filtered_idx]

# 绘制筛选后的上半部分极坐标图
polar.plot(filtered_values, polar.pos = filtered_angles, theta.lim = c(0, 180), start = 0)

内容的提问来源于stack exchange,提问作者user9328442

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:26:03