[R] lattice help required

Kay Cecil Cichini Kay.Cichini at uibk.ac.at
Mon Aug 30 15:40:48 CEST 2010


felix,
thanks a lot for the hint!

i actually found another way by setting up a panel function by which i  
can control every single panel with panel.number(). maybe there is  
more efficient coding - i don't know. i also alternated tickmarks and  
tick-labeling by panel-rows, which is nicer, but ran into the next  
trouble of not knowing how to trigger the ylabs which by default will  
be printed to only one side - i'll show code and would be happy if  
someone would point out how to put the ylabs correctly so that i'll be  
able to bring my lattice-odyssey to an end.

here's the code:

library(lattice)

y1 <- rnorm(120,100,10)
y2 <- rnorm(120,10,1)
facs<-expand.grid(Sites=rep(c("Site I","Site II","Site  
III"),20),Treatment=c("A","B"))

trellis.par.set(clip=list(panel="off",strip="off"),
                 layout.widths=list(right.padding=10,
                                   left.padding=8))

PanFun<-function(...){
			    panel.dotplot(...)
			    if(is.element(panel.number(),1:2))
  					{at<-pretty(c(min(y1),max(y1)))
                                panel.axis("right",at=at,outside=T,
                                labels = F,half=F)}
	   		    if(panel.number() == 3)
  					{at<-pretty(c(min(y1),max(y1)))
                                panel.axis("right",at=at,outside=T,
                                labels = T,half=F)
                                ylab="response y1"}    #### how to set ylabs???
			    if(panel.number() == 4)
  					{at<-pretty(c(min(y2),max(y2)))
                                panel.axis("left",at=at,outside=T,
                                labels = T,half=F)
			        ylab="response y2"}   #### how to set ylabs ???
			    if(is.element(panel.number(),5:6))
  					{at<-pretty(c(min(y2),max(y2)))
                                panel.axis("left",at=at,outside=T,
                                labels = F,half=F)}
			    }

dotplot(y1+y2 ~ Treatment|Sites,
         outer=TRUE,data=facs,
         scales = list(
	    x = list(rot = 0, tck=c(1,0)),
           y = list(draw=F,relation="free",
           limits=list(range(y1),range(y1),range(y1),
                       range(y2),range(y2),range(y2)))),
         ylab=NULL,				### this ylab argument would
         xlab=c("Site 1", "Site 2","Site 3"),	### plot only at left side..
         strip=FALSE, panel=PanFun)


Zitat von Felix Andrews <felix at nfrac.org>:

> Deepayan Sarkar has a function combineLimits() in the development
> version of the latticeExtra package (i.e. the version on
> r-forge.r-project.org) which will set common scales in each row or
> column of your layout. It can also remove the internal axes.
>
> # Felix
>
>
> On 26 August 2010 04:43, Kay Cichini <Kay.Cichini at uibk.ac.at> wrote:
>>
>> .. thanks again, richard.
>> and you swiftly saw the next problem comming up - when using par.settings =
>> list(layout.widths = list(axis.panel = c(1, 0))) getting rid of the double
>> tick labeling would be natural -
>> but i'll leave it at that for today.
>>
>> many thanks,
>> kay
>>
>>
>> Richard M. Heiberger wrote:
>>>
>>> The multiple y axes are protecting you in this situation.
>>>
>>>
>>> z <- cbind(rnorm(100,c(1,10),1), rnorm(100,c(20,30),1))
>>> dotplot(z[,1]+z[,2] ~ facs$Treatment|facs$Sites,
>>>         outer=TRUE,
>>>         scales = list(
>>>           y = list(
>>>             relation="free")),
>>>         ylab=c("y1", "y2"),
>>>         xlab=c("Site 1", "Site 2"),
>>>         strip=FALSE,
>>>         main="problem")
>>>
>>> dotplot(z[,1]+z[,2] ~ facs$Treatment|facs$Sites,
>>>         outer=TRUE,
>>>         scales = list(
>>>           y = list(
>>>             relation="free",
>>>             limits=list(c(-5,13),c(-5,13),c(18,32),c(18,32)))),
>>>         ylab=c("y1", "y2"),
>>>         xlab=c("Site 1", "Site 2"),
>>>         strip=FALSE, main="protected")
>>>
>>> For more control (such as suppressing the y-tick labels in the right-hand
>>> column,
>>> I recommend Deepayan Sarkar's book.
>>>
>>> Rich
>>>
>>>       [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> 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.
>>>
>>>
>>
>>
>> -----
>> ------------------------
>> Kay Cichini
>> Postgraduate student
>> Institute of Botany
>> Univ. of Innsbruck
>> ------------------------
>>
>> --
>> View this message in context:  
>> http://r.789695.n4.nabble.com/lattice-help-required-tp2338382p2338707.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> --
> Felix Andrews / ???
> http://www.neurofractal.org/felix/
>
>



More information about the R-help mailing list