0

ここでトリッキーなifelse仕事があります。以下は、2 つの期間 (futurecurrent) のデータを表示するコードです。データにはmean, 5th and 95th、xy 座標に沿って信頼限界があります。2 つの dfs (と) のmean, 5th and 95th信頼限界 (CI)を比較したいと思います。futurecurrent

条件:

1) CIsforfutureが のものと重複せずcurrent、 futrue の CI が現在よりも上にある場合、pch=2.

2) CIsforfutureが のものと重複せずcurrent、 futrue の CI が現在よりも下にある場合、pch=3.

3) 将来の CI が現在の CI と重複する場合、pch=4

library(raster)
library(rasterVis)

    s <- stack(replicate(2, raster(matrix(runif(100), 3))))
    current <- data.frame(coordinates(sampleRandom(s, 3, sp=TRUE)),
                     C5th=c(17.643981,16.83572,9.979904),
                     CMean=c(26.66364,19.74286,15.10000),C95th=c(35.68329,22.64999,20.22010))


    future <- data.frame(coordinates(sampleRandom(s, 3, sp=TRUE)),
                          C5th=c(17.643981,16.83572,9.979904)*2,
                          CMean=c(26.66364,19.74286,15.10000)*2,C95th=c(35.68329,22.64999,20.22010)*2)

上記の 3 つの結果がconditionsマップに追加されます。次のようなもの(単なる試み):

levelplot(s, margin=FALSE, at=seq(0, 1, 0.05)) + 
  layer(sp.points(xy, pch=ifelse(condition, 2, 3,4), cex=2, col=1), columns=1) +
  layer(sp.points(xy, pch=ifelse(condition, 2, 3,4), cex=2, col=1), columns=2)

たとえば、下の図で、NFC の最小値 ( future) が AFC の最大値 ( ) を完全に上回っているcurrent場合、条件 1. NFC の最大値が AFC の最小値を完全に下回っている場合、条件 1. プロットは次のようになります。以下は条件 3 を満たします。

ここに画像の説明を入力

助けてください。で。

4

1 に答える 1

1

SpatialPointsDataFrame必要な条件に従って定義された追加のカテゴリ変数を使用して完全なオブジェクトを定義すると、より簡単になります。

library(raster)
library(rasterVis)

s <- stack(replicate(2, raster(matrix(runif(1000), 3))))
## Coordinates
cc <- sampleRandom(s, 3, sp = TRUE)
## Data
current <- data.frame(C5th=c(17.643981,16.83572,9.979904),
                      CMean=c(26.66364,19.74286,15.10000),
                      C95th=c(35.68329,22.64999,20.22010))

future <- data.frame(C5th=c(17.643981,16.83572,9.979904)*2,
                     CMean=c(26.66364,19.74286,15.10000)*2,
                     C95th=c(35.68329,22.64999,20.22010)*2)

cf <- data.frame(current, future)
## Define a categorical variable checking the conditions you need
cf$class <- with(cf,
                 ifelse(C5th > C95th.1, 'A',
                        ifelse(C95th < C5th.1, 'B',
                               ifelse(C5th < C95th.1 && C5th > C5th.1, 'C', 'D')
                               )
                        )
                 )
cf$class <- factor(cf$class)

## Build a SPDF object with the coordinates and data
pp <- SpatialPointsDataFrame(cc, cf)

このオブジェクトは で表示できますspplot。それを使用して、シンボル、サイズなどを選択できます。

levelplot(s) + spplot(pp["class"],
                      pch = 21:23,
                      col.regions = 'gray')
于 2015-03-22T15:05:15.630 に答える