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 following
However, I need the following.
- If the contour1 (dark line from z) > contour2(the grey line from z1) the colour should be red. (which i already achieved).
- 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)).
- 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.