[R] Rotating points, preferably in grid

Thomas Levine _ at thomaslevine.com
Thu Aug 25 04:16:51 CEST 2016


I want to make a plot in polar coordinates. I want to use pch with
shapes that do not have radial symmetry, so I want to rotate them such
that they face inwards. I am using grid for my plotting, but I provide
motivating examples in graphics.

The following plot almost gets me what I want.

  theta <- 2*pi*seq(0,7/8,1/8)
  plot(cos(theta), sin(theta), pch=2, axes=F, asp=1)

But I want the points to face inwards. I can do something like this with
text, but I can set only a constant rotation

  plot.new()
  plot.window(c(-1,1),c(-1,1), asp=1)
  text(cos(theta), sin(theta), 'Tom', srt
 =runif(1,0,360))

To rotate all of the points, I can do something like this.

  plot.new()
  plot.window(c(-1,1),c(-1,1), asp=1)
  for (the.theta in theta)
    text(cos(the.theta), sin(the.theta), 'Tom',
         srt=(360/(2*pi))*(the.theta-(1/4)*2*pi))

So perhaps I could use a "T" instead of a numeric pch and consequently
do something like this.

  plot.new()
  plot.window(c(-1,1),c(-1,1), asp=1)
  for (the.theta in theta)
    text(cos(the.theta), sin(the.theta), 'T',
         srt=(360/(2*pi))*(the.theta+(1/4)*2*pi))

But that seems a bit silly.

Is there a more declarative way of doing this, preferably in grid?

Thanks



More information about the R-help mailing list