spatstat进行空间点格局分析【试玩】

#spatstat进行空间点格局分析【试玩】

# 安装spatstat
# install.packages("spatstat",dep=T)

# 加载spatstat包
library("spatstat")

# x是20个服从[0,1]上的均匀分布的变量,y也是
x <- runif(20)
y <- runif(20)
# 创建点过程
mypattern <- ppp(x, y, c(0,1), c(0,1), unitname=c("metre","metres"))

# 如果存在output.log文件,删除output.log文件
if( file.exists("output.log")){
    file.remove("output.log") 
}

con <- file("output.log") # 创建一个output.log文件
sink(con, append=TRUE) # 记录output
print("————summary start—————")
summary(mypattern)
print("————summary end—————")
# 如果不存在img目录,创建img目录
if(! dir.exists("img")){
  dir.create("img")
}
# 切换到img目录,并删除img目录下所有文件
setwd("./img")
allfile = dir()
target <- grep("*", allfile)
file.remove(allfile[target])
# 切换到上层目录
setwd("../")
print(getwd())

png("./img/mypattern.png",width = 960, height = 960,res=144)
plot(mypattern)
dev.off()


png("./img/density_estimate_for_mypattern.png",width = 960, height = 960,res=144)
plot(density(mypattern))
dev.off()

png("./img/Delaunay_triangulation.png",width = 960, height = 960,res=144)
plot(delaunay(mypattern))
dev.off()

png("./img/Voronoi_tessellation.png",width = 960, height = 960,res=144)
plot(dirichlet(mypattern))
dev.off()

png("./img/the Fest, Gest, Kest, and Jest functions of mypattern.png",width = 960, height = 960,res=144)
plot(allstats(mypattern)) 
dev.off()

png("./img/estimate_of_L_function.png",width = 960, height = 960,res=144)
plot(Lest(mypattern)) 
dev.off()

png("./img/estimate_of_pair_correlation_function.png",width = 960, height = 960,res=144)
plot(pcf(mypattern)) 
dev.off()




# 下面是草稿
# radian是一款21世纪的R语言编辑器,可以使用pip安装
# demo(spatstat)  查看spatstat的demo,很全
# 很全的spatstat文档,44页,直接从第5页的CONTENTS开始看  https://cran.r-project.org/web/packages/spatstat/spatstat.pdf
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容