在 SF 多边形中绘制箭头

plot arrows in SF polygon

在 R 中绘制从多边形的一个质心到另一个质心的弯曲箭头的正确方法是什么。

我尝试了图表包中的曲线箭头。但它在其他一些地方绘制的箭头可能是由于不同的坐标系统。

library(sf)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
plot(st_geometry(nc))
nc$centroid<- st_centroid(nc$geometry)
plot(nc$centroid, add=T, pch=3, col="red")

按照您的示例进行操作。为了简化,只使用前四个多边形:

> plot(st_geometry(nc)[1:4])

获取四个多边形质心。忽略警告:

> xy = st_coordinates(st_centroid(nc)[1:4,])
Warning messages:
1: In st_centroid.sf(nc) :
  st_centroid assumes attributes are constant over geometries of x
2: In st_centroid.sfc(st_geometry(x), of_largest_polygon = of_largest_polygon) :
  st_centroid does not give correct centroids for longitude/latitude data

并在质心之间画一些弯曲的箭头:

> curvedarrow(from=xy[2,],to=xy[1,],lcol="red", curve=.2)
> curvedarrow(from=xy[4,],to=xy[1,],lcol="red", curve=.2)

那个情节弯曲了,所以把它弄平一点:

> curvedarrow(from=xy[4,],to=xy[1,],lcol="red", curve=.12)

我已将所有质心添加到此图中,因此您可以看到它正在绘制从质心到质心的曲线。