# [R] Lattice graphics and strip function

Hanke, Alex HankeA at mar.dfo-mpo.gc.ca
Tue Feb 17 17:28:27 CET 2004

```
> -----Original Message-----
> From:	Hanke, Alex
> Sent:	Tuesday, February 17, 2004 7:26 AM
> To:	'Luke Keele'
> Subject:	RE: [R] Lattice graphics and strip function
>
> Example of how to manipulate strip text followed by code that uses special
> characters. You will probably have to pass a vector of strip text that
> utilizes expression() to the strip() function. Keep drilling down through
> the help topics on lattice functions until you understand it. Hope it
> helps.
> Alex
>
> ##########################################################################
> ###################
> postscript(file = "stagesprofile1982.eps",
> width = 7, height = 7, pointsize = 12,horizontal=F)
>     xyplot(-1*Y.factors[,2]~Y.group[,1] | factor(Y.factors[,1]),
>     ylab=list(c("Depth (m)"),cex=.8),xlab=list(c("Abundance
> log10(count+1)"),cex=.8),
>
> scales=list(cex=.6,y=list(at=seq(min(-1*Y.factors[,2]),max(-1*Y.factors[,2
> ]),10),
>
> labels=as.character(-1*seq(min(-1*Y.factors[,2]),max(-1*Y.factors[,2]),10)
>     col="black",
> par.strip.text=list(cex=.7),xlim=range(Y.group[,1]),ylim=range(-1*Y.factor
> s[,2]),
>     type="l", allow.multiple=T,
>        strip = function(..., factor.levels,
>                             which.given, which.panel, strip.names) {
>                print(factor.levels[which.panel])
>
>                strip.default(...,
>                              factor.levels = y,
>                              which.given = which.given,
>                              which.panel = which.panel,
>                              strip.names = c(F,F),
>                              style=1)},
>     panel=function(x,y,subscripts){
>     for(i in sort(unique(Y.group[subscripts,2]),dec=T)){
>     cond<-Y.group[subscripts,2]==i
>     grid.polygon(x=c(0,x[cond],0), y=c(0,y[cond],-90),
> default.units="native",
>
> gp=gpar(lwd=1,col="black",fill=c("grey50","white","grey90","grey70","grey2
> 5")[i]), draw=T, vp=NULL)
>     }
>     for(i in sort(unique(Y.group[subscripts,2]),dec=F)){
>     cond<-Y.group[subscripts,2]==i
>     llines(x=c(0,x[cond],0),y=c(0,y[cond],-90),type="l",col="black",lwd=1,
>     lty=c("blank","blank","dotted","blank","dotted")[i])
>     }},
>
> key=list(x=.8,y=.9,c(0,0),columns=1,rectangles=list(col=c("grey50","white"
> ,"grey90","grey70","grey25")),
>     cex=.6,
>     text=list(lab=c("  cyst","  fusing","  duplet","  planozygote","
> singlet"))))
>
>    dev.off()
> ##########################################################################
> ###############
> ################
> ##Fluorescence##
> ################
> Fluor.f<-function(){
> library(akima)
> x<-DEPLOY<=749
> akima.li1<-interp(DEPLOY[x],DEPTH[x],WETLABS[x],xo=seq(734,749,
> length=128),  yo=seq(0,105, length=210))
> akima.li2<-interp(DEPLOY[!x],DEPTH[!x],WETLABS[!x],xo=seq(750,761,
> length=96),  yo=seq(0,105, length=210))
> postscript(file = "fluorescencecontour2001.eps", width = 6, height = 6,
> pointsize = 12,horizontal=F)
> par(fig=c(0,.5,0,.35),plt=c(.25,.99,.16,.98),par(new=T))
> j<-1
> for(i in list(akima.li1,akima.li2)){
> image(i,ylim=c(100,1),axes=F,
>
> col=gray(c(.8,.7,.6,.5,.4,.3)),breaks=c(seq(0,10,2),20),cex.lab=.8,xlab=""
> ,ylab="")
> contour(i,levels=c(seq(0,10,2),20),ylim=c(100,1),
>     axes=F,xaxs = "i",labcex=.8)
> if(j==1){axis(side=2,at=c(1,seq(10,100,10)),labels=as.character(c(1,seq(10
> ,100,10))),par(cex.axis=1))
>
> axis(side=1,at=seq(734,748,1),labels=as.character(tapply(hour,deploy,min)[
> 1:15]),par(cex.axis=1),mgp=c(3,.2,0))
>  mtext(expression("Fluorescence ("*mu*"g chl/L)"), side = 3, line =
> 0.1,at=734, outer = F, cex = .7,adj=0)
>  mtext("Depth (m)", side = 2, line = 2,at=50, outer = F, cex =
> if(j==2){
> axis(side=1,at=seq(751,761,1),labels=as.character(tapply(hour,deploy,min)[
> 18:28]),par(cex.axis=1),mgp=c(3,.2,0))}
> box()
> par(fig=c(.5,1,0,.35),plt=c(0,.543,.16,.98),par(new=T))
> j<-j+1
> }
> dev.off()
> }
> ##########################################################################
> ###############################
> -----Original Message-----
> From:	Luke Keele
> [SMTP:luke.keele at politics-and-international-relations.oxford.ac.uk]
> Sent:	Tuesday, February 17, 2004 1:52 AM
> To:	R-help at stat.math.ethz.ch
> Subject:	[R] Lattice graphics and strip function
>
> I am looking for examples of code that demonstrates the fine tuning of
> the strip panels in lattice graphics and uses plotmath characters.  The
> code for the graphic is as follows:
>
>
>
> xyplot(lagy ~ n | rho1 * rho2, data= data, layout=c(2,6), span = 1,
>
> xlab = "Sample Size", ylab = "Bias in the Coefficient for the Lag of X",
>
> type = "o")
>
>
>
> rho1 is a four level factor and rho2 is a three level factor.
>
>
>
> The problem is that I want to use plotmath characters in the strips, but
> using the strip = function the best I so far have been able to do is
> change all the strip labels to the same character instead of it varying
> as the factors do.  Since I am using plotmath characters I am unable to
> change how R designates the factors which would be the easiest solution.
> I have read the documentation several times and am unable to decipher
> how to set the parameters for the strip function.
>
>
>
> Thanks
>
>
>
> Luke Keele
>
> Post-Doctoral Fellow in Quantitative Methods
>
> Nuffield College, Oxford University
>
> Oxford, UK
>
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help