如何用条件绘制轮廓

时间:2017-07-07 16:54:24

标签: r plot contour kernel-density

我有两个变量(z和z1)。我需要覆盖轮廓并找到它们之间的重叠和非重叠区域。

z<-matrix(c(rep(0.9,8),0.9,0.9,rep(0.8,7),0.9,0.9,0.8,rep(0.7,5),0.8,0.9,
        0.9,0.8,0.7,rep(0.6,3),0.7,0.8,0.9,0.9,0.8,0.7,rep(0.6,3),0.7,0.8,0.9
        ,0.9,0.8,0.7,rep(0.6,3),0.7,0.8,0.9,0.9,0.8,rep(0.7,5),0.8,0.9,
        0.9,rep(0.8,7),0.9),9,9)



z1<-matrix(c(rep(0.9,8),0.9,0.9,rep(0.8,7),0.9,0.9,0.8,rep(0.7,5),0.8,0.9,
            0.9,0.85,0.7,rep(0.6,3),0.65,0.85,0.9,0.9,0.8,0.7,rep(0.6,3),0.7,0.8,0.9
            ,0.9,0.85,0.7,rep(0.6,3),0.65,0.8,0.9,0.9,0.8,rep(0.7,5),0.8,0.9,
            0.9,rep(0.8,7),0.9),9,9)



levels=c(0.7,0.75,0.8,0.9)
for (lev in length(levels):2){
  .filled.contour(seq(1,9,1),seq(1,9,1),z,levels=c(levels[lev-1],levels[lev]),col="red")
  .filled.contour(seq(1,9,1),seq(1,9,1),z1,levels=c(levels[lev-1],levels[lev]),col="white")
}
contour(seq(1,9,1),seq(1,9,1),z,levels=c(0.7,0.75,0.8,0.9),add=T)
contour(seq(1,9,1),seq(1,9,1),add=T,z1,levels=c(0.7,0.75,0.8,0.9),col="grey",drawlabels=F)

运行此代码后,它将生成以下enter image description here

但是,我需要以下内容。

  1. 如果contour1(来自z的暗线)&gt; contour2(z1的灰线)颜色应为红色。 (我已经实现了)。
  2. 如果contour1&lt; contour2颜色应为蓝色,它们之间的公共区域应为白色。 (白色部分也已实现,并且无法为蓝色部分着色(参见图中,小三角形应为蓝色)。)
  3. 我还需要计算总红色区域和总蓝色区域(它也可以相对于地图)

0 个答案:

没有答案