Missing right tick marks in R latticeExtra c.trellis

190 Views Asked by At

When using latticeExtra:::c.trellis to combine plots, the right-side tick marks and text/numeric labels go missing, and I'd like to bring them back:

library(latticeExtra)

set.seed(1)
foo <- data.frame(x = 1:100, 
                  y = 1:100 + rnorm(100))
foo$resid <- with(foo, x-y)

## Plot 1 -----
(p1 <- xyplot(y~x, foo))

## Plot 2 -----
(p2 <- 
    xyplot(resid~x, foo, 
           scales = list(rot = 0, tck = c(1,1), alternating = 3),
           between = list(y = 1), ylab.right = "ylab.right", 
           # par.settings = list(axis.components = 
           #                       list(right = list(pad1 = 2, pad2 = 2)))
           # Note: this padding attempt does not restore the missing ticks,
           # pad arguments get ignored when using c.trellis below
           ))
# tick marks appear on all four sides (as desired)

## Combine -----
(p12 <- latticeExtra:::c.trellis(p2, p1,layout = c(1,2)))
# right tick marks are missing

Is there a way to restore the right-side ticks and/or labels manually, say, by modifying the combined trellis object?

1

There are 1 best solutions below

3
On

From the help file ?c.trellis:

Description

Combine the panels of multiple trellis objects into one.

and later,

Note that combining panels from different types of plots does not really fit the trellis model. Some features of the plot may not work as expected. In particular, some work may be needed to show or hide scales on selected panels. An example is given below.

It looks to me that you really aren't trying to combine panels into one object. You even use between to put some separation. Rather, you are trying to combine two plots.

You can use print,

print(p1,split=c(1,1,1,2),more=TRUE)
print(p2,split=c(1,2,1,2),more=FALSE)

See ?print.trellis.