[R-sig-Geo] matching shading and contour

Frede Aakmann Tøgersen FredeA.Togersen at agrsci.dk
Sat Apr 26 10:50:54 CEST 2008


Sorry, I just realised that my copy and pasting wasn't sufficient to understand what I'm doing.
 
My xyz object below is just a dataframe containing your xx, yy, and P. Thus you  can do this instead:
 
P.interp <- interp(xx, yy, P)

Hope that helps ;-)

Frede



________________________________

Fra: r-sig-geo-bounces at stat.math.ethz.ch på vegne af Frede Aakmann Tøgersen
Sendt: lø 26-04-2008 09:21
Til: F. De Sales; r-sig-geo at stat.math.ethz.ch
Emne: Re: [R-sig-Geo] matching shading and contour



Thank you for finally (you've asked at the r-help list too) for providing a minimal example. It makes it easier for us to help you.

Try using the interp() function from the "akima" package. E.g.

install.packages("akima")
library(akima)

dim(P)

P.interp <- interp(xyz$x, xyz$y, xyz$z)

str(P.interp)

mynl <- 20
filled.contour(P.interp$x,P.interp$y,P.interp$z,ylim=c(2,5),
   zlim=c(-1.5,1.5),nlevels=mynl,
   color=cm.colors,
   plot.axes = {
      contour(P.interp$x,P.interp$y,P.interp$z,add=T, col="grey", ylim=c(2,5),
      zlim=c(-1.5,1.5),nlevels=mynl,
      drawlabels=F)
      axis(1,1:length(xx))
      axis(2,1:length(yy))
    })

You can play with the settings of interp() together with the settings of nlevels of filled.contour() in order to get something close to what you want:

P.interp <- interp(xyz$x, xyz$y, xyz$z,
                   xo = seq(min(xyz$x), max(xyz$x), length = 100),
                   yo = seq(min(xyz$y), max(xyz$y), length = 100))

mynl <- 40, # or 10, 20, 50, .......
filled.contour(P.interp$x,P.interp$y,P.interp$z,ylim=c(2,5),
   zlim=c(-1.5,1.5),nlevels=mynl,
   color=cm.colors,
   plot.axes = {
      contour(P.interp$x,P.interp$y,P.interp$z,add=T, col="grey", ylim=c(2,5),
      zlim=c(-1.5,1.5),nlevels=mynl,
      drawlabels=F)
      axis(1,1:length(xx))
      axis(2,1:length(yy))
    })

regards Frede Aakman Tøgersen

________________________________

Fra: r-sig-geo-bounces at stat.math.ethz.ch på vegne af F. De Sales
Sendt: fr 25-04-2008 21:08
Til: r-sig-geo at stat.math.ethz.ch
Emne: [R-sig-Geo] matching shading and contour



    Hello everyone.
    Once again I need you help. How to make sure that
contour lines and shading match when using the command
filled.contour?
    This is my example:

P = array(0,c(10,5))
P [1,]= c(-0.0708, -0.09906,  0.2346,  0.1556,
-0.1136)
P [2,]= c(-0.1086, -0.07813,  0.4122,  0.3290,
-0.2537)
P [3,]= c(-0.0661, -0.16677,  0.5109,  0.6276,
-0.4118)
P [4,]= c(-0.0728, -0.05032,  0.2441,  0.7046,
-0.8731)
P [5,]= c(-0.0940,  0.00464,  0.0212,  0.3605,
-1.2655)
P [6,]= c(-0.2043, -0.18422, -0.1460,  0.0917,
-1.0035)
P [7,]= c(-0.2263, -0.17598,  0.0318, -0.0685,
-0.8082)
P [8,]= c(-0.3277, -0.16696,  0.2180, -0.0898,
-0.6687)
P [9,]= c(-0.3139, -0.19312,  0.4357, -0.1240,
-0.3028)
P[10,]= c(-0.1368,  0.15187,  0.1775,  0.0379,
-0.0158)
xx = seq(1,10)
yy = seq(1,5)
filled.contour(xx,yy,P,ylim=c(2,5),
   zlim=c(-1.5,1.5),nlevels=20,
   color=cm.colors,
   plot.axes = {
      contour(xx,yy,P,add=T, col="grey", ylim=c(2,5),
      zlim=c(-1.5,1.5),nlevels=20,
      drawlabels=F)
      axis(1,1:length(xx))
      axis(2,1:length(yy))
    })

    You can see that in the center of the plot the
contour lines do no match the shaded pink area.

    Any idea?
    Thank you again for your help.
    F. De Sales


      ____________________________________________________________________________________

[[elided Yahoo spam]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo




More information about the R-sig-Geo mailing list