Question

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
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top