【发布时间】:2018-12-01 11:06:43
【问题描述】:
我有一组纬度和经度点,我设法用它绘制了一个 voronoi 图。
我想在新加坡的 shapefile 上叠加 voronoi 图,并用地图的边界划定 voronoi 图。
我的voronoi图是:
coords <- data.frame(Lat=c(1.29370,1.37640,1.25600,1.38370,1.38240,1.31910),Long=c(103.8125,103.8492,103.6790,103.8860,103.7603,103.8191))
library(deldir)
library(ggplot2)
#This creates the voronoi line segments
voronoi <- deldir(coords$Long, coords$Lat)
#Now we can make a plot
ggplot(data=coords, aes(x=Long,y=Lat)) +
#Plot the voronoi lines
geom_segment(
aes(x = x1, y = y1, xend = x2, yend = y2),
size = 2,
data = voronoi$dirsgs,
linetype = 1,
color= "#FFB958") +
#Plot the points
geom_point(
fill=rgb(70,130,180,255,maxColorValue=255),
pch=21,
size = 4,
color="#333333")
我的地图是:
library(raster)
sg <- getData(country="SGP", level=0)
如何在地图上绘制 voronoi 图并通过地图的边界对其进行划分?
【问题讨论】: