r - Add XY points conditionally to raster map generated by levelplot -


i have tricky ifelse task here. below code showing data 2 periods(future , current). data has mean, 5th , 95th confidence bounds alongside xy cordinates. want compare mean, 5th , 95th confidence bounds (ci) 2 dfs (future , current).

conditions:

1) if cis future not overlap of current , cis of futrue above current, thenpch=2.

2) if cis future not overlap of current , cis of futrue below current, thenpch=3.

3) if cis of future overlap of current, 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) 

the result of above 3 conditions added map. (just attempt):

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) 

for example, in figure below, if minimum of nfc (future) lies above maximum of afc (current), condtion 1. if maximum of nfc lies below minimum of afc, condtion 1.the plot shown below satisfies condition 3.

enter image description here

please help. at.

it easier if define complete spatialpointsdataframe object additional categorical variable defined according conditions need.

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 categorical variable checking conditions 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 spdf object coordinates , data pp <- spatialpointsdataframe(cc, cf) 

this object can displayed spplot. can choose symbols, sizes, etc.

levelplot(s) + spplot(pp["class"],                       pch = 21:23,                       col.regions = 'gray') 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -