【发布时间】:2019-07-05 16:32:06
【问题描述】:
我喜欢使用 tmaptools 包的 smooth_map 函数计算内核密度估计值。我遵循 Chris Brunsdon 和 Lex Comber 在他们的教科书“空间分析和制图的 R 简介”中的程序。来自chapter 6 我改编了下面的代码示例。
我想为组成 smooth_map 但迄今为止无法实现的每个坐标对提取内核密度估计。
# Load GISTools (for the data) and tmap (for the mapping)
require(GISTools)
require(tmap)
require(tmaptools)
# Get the data
data(newhaven)
# look at it
# select 'view' mode
tmap_mode('view')
# Create the map of blocks and incidents
tm_shape(blocks) + tm_borders() + tm_shape(breach) +
tm_dots(col='navyblue')
# Function to choose bandwidth according Bowman and Azzalini / Scott's rule
# for use with <smooth_map> in <tmaptools>
choose_bw <- function(spdf) {
X <- coordinates(spdf)
sigma <- c(sd(X[,1]),sd(X[,2])) * (2 / (3 * nrow(X))) ^ (1/6)
return(sigma/1000)
}
# Calculate kernel density
breach_dens <- smooth_map(breach,cover=blocks, bandwidth = choose_bw(breach))
# Plot resulting polygon map
tm_shape(breach_dens$polygons) + tm_fill(col='level',alpha=0.8)+
tm_shape(blocks) + tm_borders() + tm_shape(breach) +
tm_dots(col='navyblue')
【问题讨论】:
标签: r dictionary smoothing