简体   繁体   English

错误:给出了 x、y 坐标但未指定 window (spatstat)

[英]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 :我也相信您可以在不指定xy的情况下简化命令:

## ...[previous code]...

cluster1 <- as.ppp(newtotaldf, W = win)

plot(win)
points(cluster1, pch = 20, col = "red")

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 R语言xy.coords(x,y)中的错误 - R language Error in xy.coords(x, y) 情节子图错误:xy.coords(x, y) 中的错误:&#39;x&#39; 是一个列表,但没有组件 &#39;x&#39; 和 &#39;y&#39; - Error with plotly subplot: Error in xy.coords(x, y) : 'x' is a list, but does not have components 'x' and 'y' 如何在R的spatstat包中为观察窗口几何设置坐标X和Y的范围 - how to set the ranges of coordinates X & Y for observation window geometry in spatstat package in R xy.coords(x,y,xlabel,ylabel,log)中的错误:“ x”是一个列表,但没有组件“ x”和“ y” - Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y' 来自 TS 的 HoltWinters 错误“xy.coords(x, y) 中的错误:'x' 和 'y' 长度不同” - Error with HoltWinters from a TS “Error in xy.coords(x, y) : 'x' and 'y' lengths differ” xy.coords(x,y,xlabel,ylabel,log)中的错误:对于Gamma分布图,&#39;x&#39;和&#39;y&#39;的长度不同 - Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ for Gamma distribution plot R:xy.coords(x,y,xlabel,ylabel,log)中的错误:&#39;x&#39;和&#39;y&#39;的长度不同 - R: Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ xy.coords 中的错误(x,y,xlabel,ylabel,log):“x”和“y”长度不同 - Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ 绘制折线图,​​xy.coords中的错误(x,y,xlabel,ylabel,log):&#39;x&#39;和&#39;y&#39;长度不同 - Plot a line graph, error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ xy.coords 中的错误(x,y,xlabel,ylabel,log):“x”和“y”长度不同 - Error in xy.coords(x, y, xlabel, ylabel, log): 'x' and 'y' lengths differ
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM