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

后端 未结 2 1852
离开以前
离开以前 2021-01-22 08:47

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

library(maps)
map(\"state\")
text(-80.83,35.19,\"Charlotte\",cex=.6)

I can also plot a ci

2条回答
  •  再見小時候
    2021-01-22 09:13

    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)
      lines(r*cos(angles)+x,r*sin(angles)+y)
    }
    

    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)

    plot(1,type='n',xlim=c(-2,2),ylim=c(-2,2))
    

    Then call the plotting function over your list of coordinates:

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

提交回复
热议问题