user3413262 user3413262 - 1 month ago 5
R Question

Drawing a Circle with a Radius of a Defined Distance in a Map

I am able to plot a map and caption a specific point:


I can also plot a circle centered around that point:

symbols(-80.83,35.19,circles=2, add=TRUE)

However, I would like to control the size of the circle. In particular, I want to draw a circle with a radius of 100 mile around multiple locations contained in a data.frame, matrix, or list.


You can write a function to customize how you want the circle to look. For example:

plotCircle <- function(x, y, r) {
  angles <- seq(0,2*pi,length.out=360)

Then if you had a set of coordinates in a data frame:

coords <- data.frame(x = c(-1,0,1), y = c(-1, 0.5, 1))

You can start with some initial plot (map, or empty plot, etc)


Then call the plotting function over your list of coordinates:

apply(coords,1,function(df) plotCircle(df[1],df[2],.3))