[R] xyplot() does not plot legends with "relation=free" scales
ilai
keren at math.montana.edu
Sun Apr 8 19:29:12 CEST 2012
On Sun, Apr 8, 2012 at 3:42 AM, Kaveh Vakili <kaveh.vakili at ulb.ac.be> wrote:
> Hi all,
>
> I have this problem with lattice that xyplot() won't draw some of my axis labels if the type (i.e. the relation argument) of scales is set as free. For example, in the plot below, I would want it to also show:
>
> 1. the labels E1,...E6 below the 10th panel (i.e. 3rd row, 2 col)....just as it is now done below the 12th panel....
>
You are setting your scales manually, so you need to make sure you
don't have typos. Change the line
lbl[[9]] <- lbl[[12]]<-c("E1","E2","E3","E4","E5","E6")
to
lbl[[10]] <- lbl[[12]]<-c("E1","E2","E3","E4","E5","E6")
> 2. as well as the labels (2,4,6,8) on the top of panels 1 and 3 (by "on top", i mean above the strips, as xyplot normally does by default but can't seem to be willing to do in the example below).
Same thing, I see the y axis labels for 1,3 but nothing for the at or
labels for x-axis for [[1,3]]. Note also you need the appropriate tck
argument for placing 'top-right'
>
>
> PS: i had originally posted this question on stackoverlow but since i didn't get an answer there i've deleted it there and posting it here.
My guess is you didn't get an answer before because this is a
reproducible example (thank you) but very involved. In the future try
to reduce your code to the minimum which produces the problem
behavior, you will often find that in the process of doing so you
answer your own question...
Hope this helped
Elai
>
> Happy Easter,
>
> B<-structure(list(yval = c(0.7, 0.61, 0.65, 0.63, 6.08, 0.64, 5.68,
> 6.77, 1.48, 7.71, 0.82, 1.15, 0.54, 1.01, 0.59, 4.84, 0.69, 0.71, 8.7, 0.48, 0.69, 4.81, 1.42, 1.19, 0.84, 4.89, 0.85, 0.67, 7.07, 0.66, 7.93, 0.69, 5.94, 0.47, 0.7, 0.73, 0.5, 3.62, 9.55, 4.48, 9.44, 1.06, 0.36, 0.73, 0.67, 1.4, 0.56, 7.07, 0.69, 0.42, 3.72, 0.8, 0.94, 0.66, 0.48, 6.94, 3.19, 0.84, 1.27, 1.85, 5.23, 0.75, 0.55, 4.69, 8.51, 3.98, 0.65, 4.72, 0.94, 0.86, 6.27, 3.42, 1.03, 1.83, 0.86, 8.59, 0.72, 7.92, 0.84, 0.49, 0.78, 7.31, 5.15, 0.88, 0.57, 0.95, 0.69, 8.77, 0.86, 0.82, 2.02, 6.99, 5.01, 0.84, 1.09, 1.02, 0.66, 9.23, 0.74, 2.21), xval = c(0.7, 0.61, 0.65, 0.63, 6.08, 0.64, 5.68, 6.77, 1.48, 7.71, 0.82, 1.15, 0.54, 1.01, 0.59, 4.84, 0.69, 0.71, 8.7, 0.48, 0.69, 4.81, 1.42, 1.19, 0.84, 4.89, 0.85, 0.67, 7.07, 0.66, 7.93, 0.69, 5.94, 0.47, 0.7, 0.73, 0.5, 3.62, 9.55, 4.48, 9.44, 1.06, 0.36, 0.73, 0.67, 1.4, 0.56, 7.07, 0.69, 0.42, 3.72, 0.8, 0.94, 0.66, 0.48, 6.94, 3.19, 0.84, 1.27, 1.85, 5.23, 0.75, 0.55, 4.69, 8.51, 3.98, 0.65, 4.72, 0.94, 0.86, 6.27, 3.42, !
> 1.03, 1.83, 0.86, 8.59, 0.72, 7.92, 0.84, 0.49, 0.78, 7.31, 5.15, 0.88, 0.57, 0.95, 0.69, 8.77, 0.86, 0.82, 2.02, 6.99, 5.01, 0.84, 1.09, 1.02, 0.66, 9.23, 0.74, 2.21), gval = c(1, 3, 4, 4, 1, 5, 5, 4, 6, 4, 2, 6, 4, 3, 4, 4, 3, 5, 1, 5, 1, 5, 6, 6, 6, 1, 1, 1, 1, 5, 1, 3, 4, 5, 4, 3, 5, 1, 5, 4, 5, 6, 3, 4, 3, 6, 3, 1, 2, 1, 3, 2, 1, 3, 4, 5, 4, 6, 6, 6, 5, 2, 1, 4, 5, 5, 4, 1, 1, 1, 3, 2, 2, 6, 2, 3, 3, 4, 1, 3, 2, 1, 3, 6, 5, 2, 6, 4, 2, 2, 1, 1, 5, 2, 6, 6, 3, 1, 4, 3), type = structure(c(2L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 1L, 3L, 2L,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L, 1L, 1L, 3L, 2L, 3L, 3L, 1L, 2L, 1L, 1L, 3L, 3L, 4L, 3L, 2L, 4L, 4L, 4L, 3L, 3L, 1L, 4L, 4L, 2L, 3L, 3L, 1L, 2L, 4L, 2L, 3L, 1L, 2L, 4L, 4L, 3L, 3L, 4L, 3L, 2L, 3L, 4L, 4L, 1L, 3L, 2L, 4L), .Label = c("4", "8", "12", "20"), class = "factor"), grp = c(4, 2, 2, 2, 4, 2, 2, 4, 4, 4, 4, 5, 2, 4, 5, 2, 2, 4, 5, 5, 2, 4, 5, 4, 2, 4, 2, 2, 4, 5, 4, 5, 4, 2, 5, 4, 2, 4, 5, 2, 5, 4, 2, 4, 5, 5, 5, 4, 2, 4, 2, 2!
> , 5, 2, 4, 4, 4, 2, 5, 4, 4, 2, 5, 4, 5, 2, 2, 4, 2, 2, 4, 4, 4, 4, 4, 5, 2, 5, 2, 5, 4, 4, 4, 2, 2, 4, 2, 5, 4, 4, 4, 4, 4, 4, 4, 5, 2, 5, 2, 4)), .Names = c("yval", "xval", "gval", "type", "cr", "p", "grp"), row.names = c(NA, -100L), class = "data.frame")
>
> And the code:
>
> library(lattice)
> library(robustbase)
> library(latticeExtra)
>
> typis <- c("A","B","C")
> types <- 1:4
>
> mypanel <- function(...){
> if(current.row()<3){
> panel.grid(v=-1,h=-1,col="dark grey")
> panel.xyplot(...)
> } else {
> panel.grid(v=-1,h=-1,col="dark grey")
> cl <- trellis.par.get()$superpose.line$col
> panel.bwplot(...,pch="-",cex=3,fill=cl,horizontal=FALSE,stats=adjboxStats)
> }
> }
>
>
> cl <- trellis.par.get()$superpose.line$col
> lmi <- rep(list(c(0,10)),12)
> lbl <- rep(list(NULL),12)
> lbl[[9]] <- lbl[[12]]<-c("E1","E2","E3","E4","E5","E6")
> lbl[[1]] <- lbl[[3]]<-c(2,4,6,8)
> aty <- rep(list(NULL),12)
> aty[[1]] <- aty[[9]] <- TRUE
> atx <- rep(list(NULL),12)
> atx[[12]] <- atx[[10]] <- seq(1.5,9,by=1.5)
> rtl <- c(45,0)
>
> useOuterStrips(xyplot(B$yval~B$xval|B$p*B$grp,group=B$gval,
> type=c("l","g"),lwd=2,cex.lab=1.5,as.table=TRUE,
> par.settings=list(cex=2,par.xlab.text=list(cex=1),axis.text=list(cex=1),
> par.ylab.text=list(cex=1),layout.widths=list(axis.panel=0,right.padding=4),
> layout.heights=list(axis.panel=0,top.padding=4,bottom.padding=4)),panel=mypanel,
> scales=list(y=list(axs="i",limits=lmi,relation="free",at=aty),
> x=list(relation="free",axs="i",limits=lmi,at=atx,labels=lbl,rot=rtl))))
>
> trellis.focus("panel",4,2,clip.off=TRUE,highlight=FALSE)
> panel.axis(side="right",at=c(2,4,6,8),outside=TRUE,text.cex=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