我找到了一种使用ggplot2绘制Voronoi图解段的方法:
library(deldir)
library(ggplot2)
library(ggthemes)
set.seed(123)
df <- data.frame(lat = rnorm(20,39,10),long = rnorm(20,-98,15))
voronoi <- deldir(df$long, df$lat)
ggplot(data=df, aes(x=long,y=lat)) +
geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2),size = 2,data = voronoi$dirsgs,linetype = 1,color= "#419AB0") +
geom_point(fill="#EACA3E",pch=21,size = 4,color="white") 我想知道是否可以绘制多边形整数段,但我不知道如何创建一个数据集与每个多边形的轮廓。
发布于 2014-06-19 16:51:39
下面是将线段转换为SpatialPolygons对象的简单方法。
library(rgeos)
## Convert data.frame of segment coordinates to a list of SpatialLines objects
ll <- apply(voronoi$dirsgs, 1, FUN=function(X) {
readWKT(sprintf("LINESTRING(%s %s, %s %s)", X[1], X[2], X[3], X[4]))
})
## Convert SpatialLines list to SpatialPolygons object
pp <- gPolygonize(ll)
## Plot to check that it works
set.seed=11
plot(pp, col=sample(colors(), length(pp)))

https://stackoverflow.com/questions/24311304
复制相似问题