[R] lattice contourplot line types

Andrew Beckerman a.beckerman at sheffield.ac.uk
Sun Feb 22 22:38:00 CET 2009


Sundar -

Thanks for the help!  Here is my modified code.  Just what I wanted.   
However, it is odd that the at= call in contourplot won't take a  
single value - I have had to trick it into plotting the "0" contour  
along with the 0.5 to make this work.

contourplot(preds~size+trt|Size.Name,
	data=pred.dat,layout=c(2,4),
	par.strip.text=list(cex=1.2),
	scales=list(cex=0.5),
	xlab=list("Size",cex=1.2),
	ylab=list("Treatment",cex=1.2),
	panel=function(at,lty,...){
		at.1<-c(0,0.5)
		at.2<-c(0.025,0.975)
		panel.contourplot(at=at.1,lty=1,...)
		panel.contourplot(at=at.2,lty=2,...)
		panel.grid(h=-1,v=-1,col="grey",...)})

Andrew

On 22 Feb 2009, at 21:25, Sundar Dorai-Raj wrote:

> The only way I can figure out to do this is to use two calls to
> panel.contourplot:
>
> library(lattice)
> x <- seq(-2, 2, length = 20)
> y <- seq(-2, 2, length = 20)
> grid <- expand.grid(x=x, y=y)
> grid$z <- dnorm(grid$x) * dnorm(grid$y)
> contourplot(z ~ x * y, grid,
>            panel = function(at, lty, col, ...) {
>              at.o <- at[seq(1, length(at), 2)]
>              at.e <- at[seq(2, length(at), 2)]
>              panel.contourplot(at = at.o, lty = 1, col = "blue", ...)
>              panel.contourplot(at = at.e, lty = 4, col = "red", ...)
>            },
>            at = pretty(grid$z, 10))
>
> HTH,
>
> --sundar
>
> On Sun, Feb 22, 2009 at 12:45 PM, Andrew Beckerman
> <a.beckerman at sheffield.ac.uk> wrote:
>> Dear all -
>>
>> I would like to adjust the line type of specific contours in  
>> contourplot
>> from the lattice package, but it seems like lty does not take a  
>> list in the
>> call.
>>
>> Here is my call to contourplot:
>>
>> contourplot(preds~size+trt|Size.Name,
>>       data=pred.dat,layout=c(2,4),
>>       at=c(0.025,0.5,0.975),
>>       par.strip.text=list(cex=1.2),
>>       scales=list(cex=0.5),
>>       xlab=list("Size",cex=1.2),
>>       ylab=list("Treatment",cex=1.2),
>>       panel=function(x,y,z,...){
>>               panel.contourplot(x,y,z,lwd=1,...)
>>               panel.grid(h=-1,v=-1,col="grey",...)})
>>
>> I would like to specify lty=c(2,1,2) corresponding to the
>> at=c(0.025,0.5,0.975), and have tried this in both the core part of  
>> the
>> call, and in panel.countourplot.  However, it only recognises the  
>> first
>> type.
>>
>> If there is no straightforward answer, I can provide the data.
>>
>> Best wishes,
>> Andrew
>>
>> R version 2.8.1 (2008-12-22)
>> i386-apple-darwin8.11.1
>>
>> locale:
>> en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> other attached packages:
>> [1] MASS_7.2-45     lattice_0.17-17
>>
>> loaded via a namespace (and not attached):
>> [1] grid_2.8.1
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>

++++++++++++++++++++++++++++++++++++
Dr. Andrew Beckerman
Department of Animal and Plant Sciences
University of Sheffield
Sheffield S10 2TN
UK

a.beckerman at sheffield.ac.uk




More information about the R-help mailing list