[R] Lattice: hiding only some strips
Michael Hoffman
b3i4old02 at sneakemail.com
Sat Jun 23 03:09:59 CEST 2007
Deepayan Sarkar wrote:
> On 6/22/07, Michael Hoffman <b3i4old02 at sneakemail.com> wrote:
>> I am using R 2.4.0 and lattice to produce some xyplots conditioned on a
>> factor and a shingle. The shingle merely chops up the data along the
>> x-axis, so it is easy to identify which part of the shingle a panel is
>> in by looking at the x-axis markings. I only want to have a strip at the
>> top for the factor.
>>
>> Is this possible? I looked into calculateGridLayout() and it seems to me
>> that there isn't an easy way to do it without rewriting that function
>> (and others).
>
> It's nowhere near that complicated, you just need to write your own
> strip function. E.g.,
>
> mtcars$HP <- equal.count(mtcars$hp)
>
> xyplot(mpg ~ disp | HP + factor(cyl), mtcars,
> par.strip.text = list(lines = 0.5),
> strip = function(which.given, which.panel, ...) {
> if (which.given == 2)
> strip.default(which.given = 1,
> which.panel = which.panel[which.given],
> ...)
> })
Thank you for this response. But it looks like I poorly specified the
problem. I only want to have a strip at the very top of the plot, not at
the top of each panel.
You can probably understand why I want this better if we take your
example and swap the givens around:
xyplot(mpg ~ disp | factor(cyl) * HP, mtcars,
par.strip.text = list(lines = 0.5),
strip = function(which.given, which.panel, ...) {
if (which.given == 1)
strip.default(which.given = 1,
which.panel = which.panel[which.given],
...)
})
So now I have 4, 6, and 8 at the top of every row of panels as a label
for cyl. But I don't need that--really I only need 4, 6, and 8 at the
very top (or bottom) of the plot, just like with default settings I only
get the axis labels at the top and bottom of the plot, not duplicated
for every panel.
What I want is to draw strips at the very top of the plot and not to
draw strips that are between panels.
Can this be done?
More information about the R-help
mailing list