Quadrats in Spatstat

与世无争的帅哥 提交于 2021-01-07 01:28:26

问题


I am now doing exploratory analysis and the objective is to plot a quadrat map, determine if there exists complete spatial randomness (visually and using chi-square test), etc. However, I am having trouble plotting a quadrat map. I previously asked this question that led me to reproject my data.

Here is my code:

library(rgdal) #Brings Spatial Data in R
library(spatstat) # Spatial Statistics
library(maptools)
library(raster)

# Load nyc zip code boundary polygon shapefile 
s <- readOGR("/Users/my_name/Documents/fproject/zip","zip")
nyc <- as(s,"owin")

### OGR data source with driver: ESRI Shapefile 
#Source: "/Users/my_name/Documents/project/zip", layer: "zip"
#with 263 features

# Load nyc arrests point feature shapefile
s <- readOGR("/Users/my_name/Documents/project/nycarrests/","geo1")

### OGR data source with driver: ESRI Shapefile 
#Source: "/Users/my_name/Documents/project/nycarrests", layer: "geo1"
#with 103376 features
#It has 19 fields

#Converting the dataset into a point pattern
utm <- "+proj=utm +zone=32 +datum=WGS84"
x <- spTransform(s,utm)
arrests <- as(x,"ppp")

marks(arrests) <- NULL
Window(arrests) <- nyc 
plot(arrests, main="2020", cols="dark green",pch=20)

### Quadrat density 2020 
Q <- quadratcount(arrests, nx= 3, ny=3)
plot(arrests, pch=20, cols="grey70", main="2020")  # Plot points
plot(Q, main="2020", add=TRUE)  # Add quadrat grid

Here, my data points are constrained by NYC zip code boundaries, but they do not show up on my map. What can I do to fix this?


回答1:


You are not providing much information. For example you could show (print) s (each time), or crs(s) (both with the raster package loaded)

Either way, it is almost certainly because the coordinate reference systems you are using are not the same. You change one to "UTM zone 21", but you do not change the others. They are probably different. Also, zone 21 is not appropriate for New York.



来源:https://stackoverflow.com/questions/65308879/quadrats-in-spatstat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!