Skip to content

lattice xscale.components: different ticks on top/bottom axis

2 messages · Deepayan Sarkar, Boris.Vasiliev at forces.gc.ca

#
On Fri, Mar 11, 2011 at 12:28 AM, <Boris.Vasiliev at forces.gc.ca> wrote:
Well, <top|bottom>$ticks$at is used to place the ticks, and $labels$at
is used to place the labels. They should typically be the same, but
you have changed one and not the other. Everything seems to work if
you set $ticks$at to the same values as $labels$at:


    ##  - bottom labels
+   ans$bottom$ticks$at <- seq(0,10,by=2)
    ans$bottom$labels$at <- seq(0,10,by=2)
    ans$bottom$labels$labels <- paste("B",seq(0,10,by=2),sep="-")

    ##  - top labels
+   ans$top$ticks$at <- seq(1,9,by=2)
    ans$top$labels$at <- seq(1,9,by=2)
    ans$top$labels$labels <- paste("T",seq(1,9,by=2),sep="-")
No. Unrecognized arguments are passed to the panel function only, not
to any other function. However, you can always define an inline
function:

oltc <- xyplot(y~x,data=df,
               scales=list(x=list(limits=c(0,10), at = 0:10, alternating=3)),
               xscale.components = function(...)
xscale.components.A(..., user.value=1))

Hope that helps (and sorry for the late reply).

-Deepayan
#
Deepyan,

Thank you very much for your reply.  It makes things a bit clearer.  

It other words in the list prepared by xscale.components(), vectors <top|bottom>$ticks$at and <top|bottom>$labels$at must be the same.  If only every second tick is to be labelled then every second label should be set explicitly to empty strings:

  ans$bottom$ticks$at <- seq(0,10,by=1)
  ans$bottom$labels$at <- seq(0,10,by=1)
  ans$bottom$labels$labels <- paste("B",seq(0,10,by=1),sep="-")
  # replace  "B-1", "B-3", ... with ""
  ans$bottom$labels$labels[seq(2,11,by=2)] <- ""

Sincerely,
Boris.