6

I'm trying to draw some circles and I was sort of hoping they would intersect with some points, alas...

library(maptools)
library(plotrix)
xy <- matrix(runif(20, min = -100, max = 100), ncol = 2)
distance <- spDistsN1(xy, xy[1, ])
plot(0,0, xlim = c(-100, 100), ylim = c(-100, 100), type = "n")
points(data.frame(xy))
points(xy[1, 1], xy[1, 2], pch = 16)
draw.circle(xy[1, 1], xy[1, 2], radius = distance)

The above code does the following:

  • Create 10 random points and choose one (first) point that would serve as an "anchor".
  • Calculate distance from anchor to all other points. This will be our "radius"
  • Draw circles around anchor point using above calculated distances for radii.
  • Scratch head why circles don't intersect with points that were used to calculate radii. circles don't intersect with points used to calculate distance
Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197

1 Answers1

9

This is the old aspect ratio problem that comes up from time to time when people are drawing ellipses, circles, etc.

Substituting MASS::eqscplot for plot (edit: or using asp=1: see ?par) appears to solve the problem.

Community
  • 1
  • 1
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • adding `asp=1` will only work (I think) when (as in this case) the x and y ranges are identical, `eqscplot` should work slightly more generally. – Ben Bolker Jun 12 '11 at 15:26
  • The only difference I notice is that whe using `asp = 1` the ratio is preserved (image is proportionally grown/shrunk) while in `eqscplot` it gets deformed if you resize the window. Nice find, thanks! – Roman Luštrik Jun 12 '11 at 19:01