绘制 SpatialDesign 对象

Plotting SpatialDesign object

我正在使用包 'spsurvey' 并在绘制结果时偶然发现了一些困难。 我想在多边形 'UT_ecoregions' 上绘制 'Equalsites' 中的生成点。但是,它不能直接使用带有 add= TRUE 参数的简单 plot 函数。

这是我正在使用的代码:

# Loading the required package 1====
library(spsurvey)
library(tidyverse)
# package 1 \ends----

# Loading the data that come along with the package====
 data("UT_ecoregions")

# Aggregation of the ecoregion areas per type
temp <- with(UT_ecoregions, tapply(Area_ha, Level3_Nam, sum))

set.seed(114) # to ensure the reproducibility of the exact same results

# a. Generate a list that contains specs of the survey design called 'Equaldsgn'
Equaldsgn <- list(None=list(panel=c(PanelOne=50), seltype = "Equal")) # 50 denotes the number of sample for each panel; seltype defines the type of random selection for the design.

# b. Selecting the sample
Equalsites <- grts(design = Equaldsgn, #ADlearn structure, usage, etc.
                   DesignID= "EQUAL",
                   type.frame = "area",
                   src.frame = "sf.object",
                   sf.object = UT_ecoregions,
                   maxlev = 5,
                   shapefile = FALSE)
# Visualizing the results: **this is where the problem lies**
plot(st_geometry(UT_ecoregions))
plot(st_geometry(Equalsites), add= TRUE)

所以我做了一些混乱的解决方法,如下所示:

resPoints <- Equalsites@coords
plot(st_geometry(UT_ecoregions))
points(resPoints)

它目前对我有用,但非常感谢任何其他建议!

IIRC,您需要在第一个 plot 调用中设置 reset = FALSE

plot(st_geometry(UT_ecoregions), reset = FALSE)
plot(st_geometry(Equalsites), add = TRUE)