如何在R中绘制极坐标?

问题描述 投票:0回答:4

假设(x(t),y(t))具有极坐标(√t,2πt)。为 t∈[0,10] 绘制 (x(t),y(t))。

R 中没有合适的函数来用极坐标绘图。我尝试通过给出 x=√t & y=2πt 来绘制正态图。 但结果图表并不如预期。

我从“科学编程和使用 r 模拟简介”中得到了这个问题,这本书告诉情节应该是螺旋形的。

r polar-coordinates parametric-equations
4个回答
10
投票

制作一个序列:

t <- seq(0,10, len=100)  # the parametric index
# Then convert ( sqrt(t), 2*pi*t ) to rectilinear coordinates
x = sqrt(t)* cos(2*pi*t) 
y = sqrt(t)* sin(2*pi*t)
png("plot1.png");plot(x,y);dev.off()

enter image description here

这不会显示连续字符,因此请添加线条来连接序列中的相邻点:

png("plot2.png");plot(x,y, type="b");dev.off()

enter image description here


3
投票

正如之前的评论中已经提到的,R 可以使用极坐标进行绘图。 plotrix 包有一个名为 Polar.plot 的函数可以执行此操作。极坐标由长度和角度定义。该函数可以采用一系列长度和一系列角度来用极坐标进行绘制。例如制作一个螺旋:

library(plotrix)
plt.lns <- seq(1, 100, length=500)
angles <- seq(0, 5*360, length=500)%%360
polar.plot(plt.lns, polar.pos=angles, labels="", rp.type = "polygon")

1
投票

值得一试的选择,它是Plotly包。

library(plotly)

p <- plot_ly(plotly::mic, r = ~r, t = ~t, color = ~nms, alpha = 0.5, type = "scatter")

layout(p, title = "Mic Patterns", orientation = -90)

注意:如果您使用 RStudio,绘图将显示在“查看器”选项卡中。


0
投票

你可以用复数来做到这一点:

t <- seq(0,10, len=100)  # the parametric index

plot(complex(modulus =sqrt(t), argument = 2*pi*t), type="b")

© www.soinside.com 2019 - 2024. All rights reserved.