首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用RandomFields软件包绘制随机高斯场的实现会产生空白图形。为什么?

使用RandomFields软件包绘制随机高斯场的实现会产生空白图形。为什么?
EN

Stack Overflow用户
提问于 2017-03-29 21:16:55
回答 1查看 560关注 0票数 3

由于某些原因,当我尝试使用plot()函数来可视化RandomFields包中RFsimulate()函数的输出时,输出总是一个空图。

我只是使用帮助文件中包含的示例代码:

代码语言:javascript
复制
## first let us look at the list of implemented models
RFgetModelNames(type="positive definite", domain="single variable",
                iso="isotropic") 

## our choice is the exponential model;
## the model includes nugget effect and the mean:
model <- RMexp(var=5, scale=10) + # with variance 4 and scale 10
  RMnugget(var=1) + # nugget
  RMtrend(mean=0.5) # and mean

## define the locations:
from <- 0
to <- 20
x.seq <- seq(from, to, length=200) 
y.seq <- seq(from, to, length=200)

simu <- RFsimulate(model=model, x=x.seq, y=y.seq)
str(simu)

这就给出了:

代码语言:javascript
复制
Formal class 'RFspatialGridDataFrame' [package ""] with 5 slots
  ..@ .RFparams  :List of 5
  .. ..$ n         : num 1
  .. ..$ vdim      : int 1
  .. ..$ T         : num(0) 
  .. ..$ coordunits: NULL
  .. ..$ varunits  : NULL
  ..@ data       :'data.frame': 441 obs. of  1 variable:
  .. ..$ variable1: num [1:441] 4.511 2.653 3.951 0.771 2.718 ...
  ..@ grid       :Formal class 'GridTopology' [package "sp"] with 3 slots
  .. .. ..@ cellcentre.offset: Named num [1:2] 0 0
  .. .. .. ..- attr(*, "names")= chr [1:2] "coords.x1" "coords.x2"
  .. .. ..@ cellsize         : Named num [1:2] 1 1
  .. .. .. ..- attr(*, "names")= chr [1:2] "coords.x1" "coords.x2"
  .. .. ..@ cells.dim        : int [1:2] 21 21
  ..@ bbox       : num [1:2, 1:2] -0.5 -0.5 20.5 20.5
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
  .. .. ..$ : chr [1:2] "min" "max"
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
  .. .. ..@ projargs: chr NA

..。所以数据已经被模拟了,但是当我调用

代码语言:javascript
复制
plot(simu)

我最终得到了这样的结果:

e.g. Empty plot

有人能说出这里发生了什么吗?!

EN

回答 1

Stack Overflow用户

发布于 2018-08-16 04:32:37

我会强制对象返回到一个sp SpatialGridDataFrame并绘制它,因为RandomFields在这个S4类周围创建了一个包装器:

代码语言:javascript
复制
sgdf = sp::SpatialGridDataFrame(simu@grid, simu@data, simu@proj4string)
sp::plot(sgdf)

此外,您还可以使用标准图形库强制转换为矩阵和绘图:

代码语言:javascript
复制
graphics::image(as.matrix(simu))

奇怪的是,将其转换为SpatialGridDataFrame需要在绘图之前进行翻转和转置:

代码语言:javascript
复制
graphics::image(t(apply(as.matrix(sgdf), 1, rev)))

显然,它们在内部有点不一致。最简单的解决方案是将simu转换为rasterplot

代码语言:javascript
复制
r = raster::raster(simu)
raster::plot(r)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43094652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档