Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a point in polar coordinates with negative r?

Tags:

r

ggplot2

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

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

enter image description here

UPDATE:

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:

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.

like image 431
Dambo Avatar asked Jul 15 '19 01:07

Dambo


People also ask

Can an r value be negative polar coordinates?

In the polar coordinate system, the ordered pair will now be (r, θ). The ordered pair specifies a point's location based on the value of r and the angle, θ, from the polar axis. The value of r can be positive, negative, or zero.

What is the point (- 3 3 in polar coordinates?

As (-3,3) lies in I Quadrant, θ=34π(r,θ)⟹(32, ,43π)or,(32 ,135°)


1 Answers

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

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

like image 156
Elio Campitelli Avatar answered Oct 11 '22 15:10

Elio Campitelli