[英]Error: x,y coords given but no window specified (spatstat)
I am generating a landscape pattern that evolves over time.我正在生成一个随时间演变的景观模式。 The problem with the code is that I have clearly defined a window for the object bringing up the error but the window is not being recognised.代码的问题是我已经为 object 明确定义了一个 window 来引发错误,但是 window 没有被识别。 I also do not see how any points are falling outside of the window, or how that would make a difference.我也看不出有什么点落在 window 之外,或者这会有什么不同。
library(spatstat)
library(dplyr)
# Define the window
win <- owin(c(0, 100), c(0, 100))
# Define the point cluster
cluster1 <- rMatClust(kappa = 0.0005, scale = 0.1, mu = 20,
win = win, center = c(5,5))
# define the spread of the points
spread_rate <- 1
new_nests_per_year<-5
years<-10
# Plot the initial cluster
plot(win, main = "Initial cluster")
points(cluster1, pch = 20, col = "red")
newpoints<-list()
# Loop for n years
for (i in 1:years) {
# Generate new points that spread from the cluster
newpoints[[1]] <-rnorm(new_nests_per_year, mean = centroid.owin(cluster1)$y, sd = spread_rate)
newpoints[[2]] <-rnorm(new_nests_per_year, mean = centroid.owin(cluster1)$x, sd = spread_rate)
# Convert the list to a data frame
newpoints_df <- data.frame(newpoints)
# Rename the columns of the data frame
colnames(newpoints_df) <- c("x", "y")
# Combine the new points with the existing points
cluster1_df <- data.frame(cluster1)
newtotaldf<-bind_rows(cluster1_df,newpoints_df)
cluster1<-as.ppp(newtotaldf, x = newtotaldf$x, y = newtotaldf$y,
window = win)
# Plot the updated cluster
plot(win, main = paste("Cluster after year", i))
points(cluster1, pch = 20, col = "red")
}
However, when I run line:但是,当我运行时:
cluster1<-as.ppp(newtotaldf, x = newtotaldf$x, y = newtotaldf$y,
window = win)
I recieve the error:我收到错误:
Error: x,y coords given but no window specified
Why would this be the case?为什么会这样?
In your code, if you use the command W = win
it should solve the issue.在您的代码中,如果您使用命令W = win
它应该可以解决问题。 I also believe you can simplify the command without specifying x
and y
:我也相信您可以在不指定x
和y
的情况下简化命令:
## ...[previous code]...
cluster1 <- as.ppp(newtotaldf, W = win)
plot(win)
points(cluster1, pch = 20, col = "red")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.