Skip to content
Prev 274608 / 398506 Next

right justify right-axis tick values in lattice

Hi,

You could also pad the text labels with phantom 0s,

ghostrighter <- function(x, ...){
  n <- sapply(x, nchar)
  nmax <- max(n)

  padaone <- function(ii){
    si <- paste(rep("0", length= nmax - n[ii]), collapse="")
    as.expression(bquote(phantom(.(si)) * .(x[ii]) ))
  }
  sapply(seq_along(x), padaone)
}

## ghostrighter(c(1, 23, 145))

panel.right<- function(x, y, ...) {
  panel.barchart(x, y, ...)
  print(x);print(y)
  panel.axis(side="right", at=pretty(y), lab=ghostrighter(pretty(y)),
outside=TRUE)
}
mybar<- function(...) {
  args<- list(...)
  args$par.settings=list(clip=list(panel="off"))
  args$par.settings$layout.widths$axis.key.padding<- 4
  do.call("barchart", args)
}
mybar(c(1,10,100,10,1) ~ "abcd", panel=panel.right, ylab.right="right")

HTH,

baptiste
On 17 October 2011 13:12, Paul Murrell <p.murrell at auckland.ac.nz> wrote: