[R] L-shaped boxes with lattice graphs?

Felix Andrews felix at nfrac.org
Wed Nov 17 07:26:34 CET 2010


Here is a better approach that will keep the axis ticks as well on the two axes.

## define a lattice "axis function"
axis.L <-
    function(side, ..., line.col)
{
    if (side %in% c("bottom", "left")) {
        col <- trellis.par.get("axis.text")$col
        axis.default(side, ..., line.col = col)
        if (side == "bottom")
            grid::grid.lines(y = 0)
        if (side == "left")
            grid::grid.lines(x = 0)
    }
}

## hide panel and strip borders by using col = NA
sty <- list()
sty$axis.line$col <- NA
sty$strip.border$col <- NA
sty$strip.background$col <- NA

xyplot(11:14 ~ 1:4 | rep(c("A", "B"), 2),
    axis = axis.L,
    par.settings = sty,
    scales=list(alternating=FALSE, relation="sliced"),
    layout=c(1,2))


Cheers
-Felix


On 16 November 2010 16:22, John Maindonald <john.maindonald at anu.edu.au> wrote:
> Hi Felix -
> There's just a slight problem.  This removes the tick marks.
> I suppose I could add a layer that has the tick marks!
> Cheers
> John.
>
> John Maindonald             email: john.maindonald at anu.edu.au
> phone : +61 2 (6125)3473    fax  : +61 2(6125)5549
> Centre for Mathematics & Its Applications, Room 1194,
> John Dedman Mathematical Sciences Building (Building 27)
> Australian National University, Canberra ACT 0200.
> http://www.maths.anu.edu.au/~johnm
>
> On 15/11/2010, at 5:45 PM, Felix Andrews wrote:
>
>> Hi John,
>>
>> Here is an example with plot borders on the left and bottom only.
>>
>> ## hide the usual panel and strip borders by using "transparent" NA
>> sty <- list()
>> sty$axis.line$col <- NA
>> sty$strip.border$col <- NA
>> sty$strip.background$col <- NA
>>
>> xyplot(11:14 ~ 1:4 | rep(c("A", "B"), 2),
>>    scales=list(x=list(alternating=FALSE, relation="sliced")),
>>    par.settings = sty,
>>    panel = function(...) {
>>        grid::grid.lines(x = 0); grid::grid.lines(y = 0)
>>        panel.xyplot(...)
>>    },
>>    layout=c(1,2))
>>
>> Hope that helps
>>
>> -Felix
>>
>>
>> On 15 November 2010 11:00, John Maindonald <john.maindonald at anu.edu.au> wrote:
>>> Can anyone suggest an equivalent, for lattice graphs,
>>> of the base graphics argument bty="l"?
>>>
>>> NB that I am leaving off the box around the strip,
>>> with a strip function:
>>> stripfun <- function(which.given,which.panel,
>>>                         factor.levels=as.expression(levlist), ...){
>>>      panel.text(x=0, y=0.5,
>>>                 lab = as.expression(levlist[which.panel[which.given]]), adj=0)
>>>    }
>>>
>>> e.g.
>>> levlist <- list("A", "B")
>>> xyplot(11:14 ~ 1:4 | rep(1:2,2), scales=list(x=list(alternating=c(1,1), relation="sliced")), strip=stripfun, layout=c(1,2))
>>>
>>>
>>> John Maindonald             email: john.maindonald at anu.edu.au
>>> phone : +61 2 (6125)3473    fax  : +61 2(6125)5549
>>> Centre for Mathematics & Its Applications, Room 1194,
>>> John Dedman Mathematical Sciences Building (Building 27)
>>> Australian National University, Canberra ACT 0200.
>>> http://www.maths.anu.edu.au/~johnm
>>>
>>> ______________________________________________
>>> 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/
>
>



-- 
Felix Andrews / 安福立
http://www.neurofractal.org/felix/



More information about the R-help mailing list