2013-08-30 50 views
0

使用splancs包中的csr函数为美国大陆生成点模式时,我发现密歇根湖和伊利湖的一小部分生成了一些点。下面是一个例子。splancs包中的csr函数在多边形外部生成点

# Load packages 
library(maps) 
library(ggplot2) 
library(splancs) 

# Obtain coordinates of US polygon 
usa <- map_data("usa") 
country <- usa[c(1,2)] 
colnames(country) <- c("x", "y") 
country <- as.points(country) 

# Generate points under complete spatial randomness 
random <- csr(country, 30000) 
random <- data.frame(random) 

# Obtain coordinates of state outlines 
state <- map_data("state") 

# Plot the points on a map of the US 
p <- ggplot(state, aes(x = long, y = lat)) + 
geom_path(color = "black", aes(group = group)) + 
geom_point(data = random, size = 0.7, aes(x = xc, y = yc), color = "gray") + 
theme_bw() 
p 

上述代码生成的地图在密歇根湖和伊利湖上清楚地显示了一些要点。有什么办法可以防止这种情况发生?

回答

0

Splancs'csr函数只适用于简单的单环多边形。为了看看到底是什么你喂养它,使用polymap

polymap(country) 

enter image description here

哎呀。你的国家多边形在它有一些古怪。获得更好的多边形。