如何用负r在极坐标中绘制点? [英] How to draw a point in polar coordinates with negative r?

查看:260
本文介绍了如何用负r在极坐标中绘制点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在极坐标(r,theta)中绘制两个点,其中r是距中心的距离,theta是角度.

I am trying to draw two points in polar coordinates (r, theta), where r is a distance from the center, and theta the angle.

当前解决方案不起作用,因为我没有轴的唯一原点".使用coord_plane时,y的原点是圆的中心,但是x的原点似乎是每个半径的中心.

The current solution does not work because I don't have a unique "origin" of the axes. When using coord_plane, the origin of y is the center of the circle, but the origin of x seems to be the center of each radius.

我想做的是在一个系统中进行绘制,该系统中以下示例中的两个点相对于原点是对称的.

What I am trying to do, is to plot in a system where the two points from the below example are symmetric with respect to the origin.

library(ggplot2)
ggplot(data.frame(r = c(-100, 100) , theta = c(1, 1)),
       aes(x = r, y= theta)) +
  geom_text(aes(label = paste(round(r, 1),',', round(theta, 1)))) +
  coord_polar(theta = 'y',
              direction = -1,
              start = -pi/2) +
  scale_y_continuous(limits = c(0, 2*pi),
                     breaks = c(0, pi/2, pi, 3*pi/2 ),
                     labels = c('0', 'pi/2', 'pi', '3/2pi'))

更新:

虽然coord_polar创建的系统可能不是直的"极地系统,但这是图形语法的引言,部分引用了coord_polar的行为,以及我必须这样做的原因.修正y的限制:

While the system that coord_polar creates is probably not a "straight" polar systems, here is a quote from the grammar of graphics that in part explains in part the behavior of coord_polar, and the reason why I had to fix the limits of y:

我们可以将极坐标视为所有其他方法的例外 秤在此系统中处理.也就是说,我们可以解释角度 绝对值以弧度表示.如果我们所有人 图形是涉及数学或工程的应用程序 弧度.但是,我们选择不这样做,以便我们可以隐藏 进行坐标转换时缩放比例详细信息.这使它 例如,可以很容易地用极坐标表示每年的时间.在 极坐标转换,因此,我们将0弧度与 最小刻度值,以数据单位(度,弧度,比例, 等)和最大2S弧度.循环参数,一起 在比例函数中使用最小和最大参数,我们可以创建 如果愿意,我们可以将极坐标图旋转一圈以上.

We could treat polar coordinates as an exception to the way all other scales are handled in this system. That is, we could interpret angular values ab- solutely as radians. This would make sense if all our graphics were mathemat- ical or engineering applications involving radians. We have chosen not to do this, however, so that we can hide scaling details when doing coordinate con- versions. This makes it easy, for example, to represent yearly time in polar co- ordinates. In the polar coordinate conversion, therefore, we align 0 radians with the minimum scale value in data units (degrees, radians, proportions, etc.) and 2S radians with the maximum. The cycle parameter, together with min and max parameters in the scale functions allows us to create polar graphs with more than one revolution if we wish.

推荐答案

我不完全了解您的最终目标是什么,但是可能的问题是,如果您希望r表示到原点的距离,那么它不能为负. ggplot2使用coord_polar()所做的只是使整个笛卡尔平面遵循极坐标变形.这导致零"实际上是径向"坐标的下限.如果您手动更改其限制,则可以清楚地看到它:

I don't fully understand what is your ultimate goal, but maybe the problem is that if you want r to represent distance to the origin, then it cannot be negative. What ggplot2 does with coord_polar() is just to deform the whole cartesian plane following polar coordinates. This results in a "zero" that is actually the lower limit of your "radial" coordinate. You can see it clearly if you manually change its limits:

library(ggplot2)
ggplot(data.frame(r = c(-100, 100) , theta = c(1, 1)),
       aes(x = r, y= theta)) +
  geom_text(aes(label = paste(round(r, 1),',', round(theta, 1)))) +
  coord_polar(theta = 'y',
              direction = -1,
              start = -pi/2) +
  scale_y_continuous(limits = c(0, 2*pi),
                     breaks = c(0, pi/2, pi, 3*pi/2 ),
                     labels = c('0', 'pi/2', 'pi', '3/2pi')) +
  scale_x_continuous(limits = c(-200, NA))

我不知道您所说的关于原点对称"是什么意思,但是这可以吗?

I don't know exactly what you mean with "symmetric with respect to the origin" but something this would be ok?

library(ggplot2)
ggplot(data.frame(r = c(100, 100) , theta = c(1, 1 + pi)),
       aes(x = r, y= theta)) +
  geom_text(aes(label = paste(round(r, 1),',', round(theta, 1)))) +
  coord_polar(theta = 'y',
              direction = -1,
              start = -pi/2) +
  scale_y_continuous(limits = c(0, 2*pi),
                     breaks = c(0, pi/2, pi, 3*pi/2 ),
                     labels = c('0', 'pi/2', 'pi', '3/2pi')) +
  scale_x_continuous(limits = c(0, NA))

reprex软件包(v0.3.0)

Created on 2019-07-16 by the reprex package (v0.3.0)

这篇关于如何用负r在极坐标中绘制点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆