[R] lattice contourplot line types
Sundar Dorai-Raj
sdorairaj at gmail.com
Sun Feb 22 22:25:35 CET 2009
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.
>
More information about the R-help
mailing list