Equal number of cuts in a contourplot with trellis

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Equal number of cuts in a contourplot with trellis

Jesus Frias
Dear R-helpers,

        I need some help to produce a set of contour plots that I am
trying to make in order to compare surfaces between the levels of a
factor. For example:

library(lattice)
g <- expand.grid(x = 60:100, y = 1:25, ti = c("a","b","c"))
g$z <-with(g,
  (-1e-4*x-1e-3*y-1e-5*x*y)*(ti=="a") +
  (1e-2*x-1e-3*y-1e-4*x*y)*(ti=="b") +
  (1e-3*x-1e-3*y-1.e-5*x*y)*(ti=="c")
               )

contourplot(z~ x * y|ti, data = g,
            cuts=20,
            pretty=T,
            screen = list(z = 30, x = -60))

As you can see in the figure, most of the contour lines are in one of
the levels and we are not able to see how the other levels look like.

I would like to display the same number of cuts in each of the trellis.
I can make each of the contourplots separately and control the number of
cuts but I am not able to plot all of them in one.

Thanks in advance,

Jesus

Jesús María Frías Celayeta
School of Food Science and Environmental Health
Dublin Institute of Technology
Cathal Brugha St. Dublin 1
p + 353 1 4024459
f + 353 1 4024495
w http://www.dit.ie/DIT/tourismfood/science/



--
This message has been scanned for content and
viruses by the DIT Information Services MailScanner
Service, and is believed to be clean.
http://www.dit.ie

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Equal number of cuts in a contourplot with trellis

Deepayan Sarkar
On 1/12/06, Jesus Frias <[hidden email]> wrote:

> Dear R-helpers,
>
> I need some help to produce a set of contour plots that I am
> trying to make in order to compare surfaces between the levels of a
> factor. For example:
>
> library(lattice)
> g <- expand.grid(x = 60:100, y = 1:25, ti = c("a","b","c"))
> g$z <-with(g,
>   (-1e-4*x-1e-3*y-1e-5*x*y)*(ti=="a") +
>   (1e-2*x-1e-3*y-1e-4*x*y)*(ti=="b") +
>   (1e-3*x-1e-3*y-1.e-5*x*y)*(ti=="c")
>                )
>
> contourplot(z~ x * y|ti, data = g,
>             cuts=20,
>             pretty=T,
>             screen = list(z = 30, x = -60))
>
> As you can see in the figure, most of the contour lines are in one of
> the levels and we are not able to see how the other levels look like.
>
> I would like to display the same number of cuts in each of the trellis.
> I can make each of the contourplots separately and control the number of
> cuts but I am not able to plot all of them in one.

The simplest solution is to recompute the levels for each panel function:

contourplot(z~ x * y|ti, data = g,
            label.style = "align",
            panel = function(x, y, z, subscripts, at, ...) {
                at <- pretty(z[subscripts], 10)
                panel.contourplot(x, y, z,
                                  subscripts = subscripts,
                                  at = at,
                                  ...)
            })

Alternatively, you could pass in a suitable 'at' vector computed externally.

Deepayan
--
http://www.stat.wisc.edu/~deepayan/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html