如何在 R 中绘制极坐标?

How to plot polar coordinates in R?

假设(x(t),y(t))的极坐标为(√t,2πt)。为 t∈[0,10].

绘制 (x(t),y(t))

R 中没有使用极坐标绘图的适当函数。我通过给出 x=√t & y=2πt 来尝试正常绘图。 但是生成的图形并不像预期的那样。

我从 "Introduction to Scientific Programming  and Simulation using r" 那里得到了这个问题,这本书告诉我情节应该是螺旋式的。

制作一个序列:

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

这不显示顺序字符,因此添加线以连接顺序中的相邻点:

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

正如之前评论中提到的,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")

一个值得一试的选项,它是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,绘图将显示在“查看器”选项卡中。