Re: [R] lattice: par.settings: custom axis.line by panel

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Fri, 08 Apr 2011 09:56:38 +0530

On Fri, Apr 8, 2011 at 6:10 AM, Benjamin Tyner <btyner_at_gmail.com> wrote:
> Hello,
>
> In lattice, is there a way to customize the axis.line by panel? For example,
> say I have two panels:
>
> Data <- data.frame(x=runif(10),
>                  y=rnorm(10),
>                  f=gl(2,5)
>                  )
>
> library(lattice)
> plot <- xyplot(y ~ x|f,
>              data = Data,
>              layout=c(2,1),
>              scales=list(relation="free",alternating=FALSE),
>              par.settings = list(axis.line=list(lwd=0))
>              )
>
> and desire lwd=0 for one panel and lwd=1 for the other. Can it be done?

No.

> If not, can the desired behavior be mimicked by explicit use of (say)
> grid::grid.rect() within the panel function?

Yes, but using the axis function would be better as panel function clips by default (so technically only half of each line would be visible).

xyplot(y ~ x|f,

       data = Data,
       layout=c(2,1),
       scales=list(relation="free",alternating=FALSE),
       par.settings = list(axis.line=list(col = "transparent")),
       axis = function(side, ...) {
           ## axis is called 4 times per panel; draw box only once
           if (side == "bottom")
           {
               box.lty <-
                   if (panel.number() %in% c(1)) # add others as needed
                       0
                   else
                       1
               grid::grid.rect(gp = grid::gpar(lty = box.lty))
           }
           axis.default(side = side, ...)
       })

-Deepayan



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. Received on Fri 08 Apr 2011 - 04:36:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 09 Apr 2011 - 01:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive