biomod2 未绘制数据

问题描述 投票:0回答:1

我正在尝试运行一个基本物种分布模型,并且

biomod2
没有绘制我的存在数据。我可以尝试在这里重现问题,但显然我无法上传我正在使用的 tif 文件。为了测试它,我简单地创建了一个与哥伦比亚的垂直直线相对应的经度/纬度值矩阵,如下所示:

tmp <- seq(-1,10,0.01) # latitude
tmp2 <- rep(-75,length(tmp)) # longitude
testVec <- cbind(tmp2,tmp)
myRespXY <- testVec

这些是我的存在数据的坐标。然后我使用状态数据,所以我

myResp <- as.numeric(rep(1,nrow(myRespXY)))

然后,使用

biomod2

的格式化功能
myBiomodData <- BIOMOD_FormatingData(resp.var = myResp, # presence data (all 1's)
                                 expl.var = myExpl, # RasterStack
                                 resp.xy = myRespXY, # coordinates of presences, corresponding to a vertical line in Colombia
                                 resp.name = myRespName) # name of species
plot(myBiomodData)

map

我做错了什么?

biomod2
正在读取存在,有时它会绘制一些点,但它不会绘制大部分点。如何获得输出来绘制所有存在数据?

r bioinformatics biomod2
1个回答
2
投票

这不是软件包的错误,而是当您使用环境变量的高分辨率栅格时出现的图形问题。

默认情况下,绘图函数根据类别(存在/不存在/未定义)对像素进行着色。因为这里的像素太小(与未定义的区域相比,存在/不存在的区域太少),我们无法真正在图中看到不同的颜色。

解决方法是从

BIOMOD_FormatingData()
输出中提取存在/不存在,使用
points
包中的
raster
函数将其显示在地图顶部。

这是一个简单的可重现示例:

##' This script is designed to show how you can simply extract presences, absences and pseudo absences
##' from a `data.formatted.Biomod.object` object (output of `BIOMOD_FormatingData()`).
##' 
##' This can be particularly useful to produce custom plots when high resolution rasters are used within `biomod2` framework.
##' 
##' 
##' ### Data formatting
##' 
##' Here we sill create a toy `data.formatted.Biomod.object` object using `BIOMOD_FormatingData()`
##' function.
##' 
##' Here are couple parameters used for the data formatting procedure:
##' 
##'   - *species* : Gulo Gulo
##'   - *explanatory variables*: [worlclim bioclimatic variables](http://www.worldclim.org/bioclim) 
##'   (bio_3, bio_4, bio_7, bio_11 & bio_12)
##'   - *numbeer of absences*: 0
##'   - *number of pseudo absences*: 500
##'   - *number of pseudo absences sampling repetiton*: 2
##'   - *pseudo absences selection algorithm*: `random`
##'   

library(biomod2)

# species occurrences
DataSpecies <- read.csv(system.file("external/species/mammals_table.csv",
                                    package="biomod2"), row.names = 1)
head(DataSpecies)

# the name of studied species
myRespName <- 'GuloGulo'

# the presence/absences data for our species
myRespDF <- DataSpecies[DataSpecies[, myRespName] == 1 ,c("X_WGS84","Y_WGS84", myRespName)]

myResp <- as.numeric(myRespDF[,myRespName])

# the XY coordinates of species data
myRespXY <- myRespDF[,c("X_WGS84","Y_WGS84")]


# Environmental variables extracted from Worldclim (bio_3, bio_4, bio_7, bio_11 & bio_12)
myExpl = raster::stack( system.file( "external/bioclim/current/bio3.grd",
                                     package="biomod2"),
                        system.file( "external/bioclim/current/bio4.grd",
                                     package="biomod2"),
                        system.file( "external/bioclim/current/bio7.grd",
                                     package="biomod2"),
                        system.file( "external/bioclim/current/bio11.grd",
                                     package="biomod2"),
                        system.file( "external/bioclim/current/bio12.grd",
                                     package="biomod2"))

# Formatting data in biomod2 friendly sahpe
myBiomodData <- BIOMOD_FormatingData(resp.var = myResp,
                                     expl.var = myExpl,
                                     resp.xy = myRespXY,
                                     resp.name = myRespName,
                                     PA.nb.rep = 2,
                                     PA.nb.absences = 500)

##'
##' ## The extraction funcrtions
##'
##' Here are define 2 small function that will help you to extract the points locations of a 
##' `data.formatted.Biomod.object`
##' 
##' **note**: This function will be integreted in a next release of `biomod2`
##'  

library(dplyr)

## function to get PA dataset
get_PAtab <- function(bfd){
  dplyr::bind_cols(
    x = bfd@coord[, 1],
    y = bfd@coord[, 2],
    status = [email protected],
    bfd@PA
  )
}

## function to get background mask
get_mask <- function(bfd){
  [email protected]
}

##'
##' ### Extract presences, absences and pseudo-absences tables
##'

##'
##' When you have extracted the PA table from `data.formatted.Biomod.object` you can easily select 
##' presences (`filter(status == 1)`), pseudo-absences (`filter(is.na(status))`) or absences 
##' (`filter(status == 0)`) even if no absences are dfined in our case
##'

## get the coordiantes of presences
(pres.xy <- get_PAtab(myBiomodData) %>% 
    filter(status == 1) %>%
    select(x, y))

## get the coordiantes of absences ==> No absences here
(abs.xy <- get_PAtab(myBiomodData) %>% 
    filter(status == 0) %>%
    select(x, y))

## get the coordiantes of pseudo - absences
## all repetition of pseudo absences sampling merged 
(pa.all.xy <- get_PAtab(myBiomodData) %>% 
    filter(is.na(status)) %>%
    select(x, y)) %>%
    distinct()
## pseudo absences sampling for the first repetition only 
(pa.1.xy <- get_PAtab(myBiomodData) %>% 
    filter(is.na(status) & PA1 == TRUE) %>%
    select(x, y)) %>%
    distinct()

##'
##' ### Plot example
##'

##' 
##' Here is an example of plot that could be usefull when resolution is too high and presences 
##' could not be diplayed correctly using the `data.formatted.Biomod.object` `plot()` function
##' 


## plot the first PA selection and add the presences on top
plot(get_mask(myBiomodData)[['PA1']])
points(pres.xy, pch = 11)

这应该给你一个像这样的情节:

© www.soinside.com 2019 - 2024. All rights reserved.