2

I have two variables (z and z1). I need to overlay the contours and find the overlapping and non overlapping area between them.

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)

after running this code, it will generate the followingenter image description here

However, I need the following.

  1. If the contour1 (dark line from z) > contour2(the grey line from z1) the colour should be red. (which i already achieved).
  2. If the contour1 < contor2 the color should be blue and the common area between them should be white. (the white part is also achieved and couldn't colour the blue part (see the figure, the small triangle should be blue)).
  3. I also need to calculate the total red area and total blue area (it can be relative to map as well)

Any help would be much appreciated.

user3978632
  • 283
  • 4
  • 17
  • 1
    https://i.stack.imgur.com/nzNJo.png I can't run this, I can't help you. – JAD Jul 06 '17 at 12:53
  • @JarkoDubbeldam I have the same question here https://stackoverflow.com/questions/44903690/2d-kde2d-contour-plots-with-conditions with the reproducible example. Check and let me know. – user3978632 Jul 06 '17 at 12:58
  • @bouncyball please check this post https://stackoverflow.com/questions/44903690/2d-kde2d-contour-plots-with-conditions. I have the reproducible example there. – user3978632 Jul 06 '17 at 13:04
  • 2
    It still is not clear what `v1`, `v2`, `z1`, and `z2` are. – JAD Jul 06 '17 at 13:04
  • @JarkoDubbeldam thanks for helping me. By v1 and v2 i just mean any two random variable. and z1 and z2 are their densities. I have described that in the post https://stackoverflow.com/questions/44903690/2d-kde2d-contour-plots-with-conditions, if you read that post, you will get the idea what i want. Its the same plot but with reproducible example. – user3978632 Jul 06 '17 at 13:08

0 Answers0