Skip to content

Instantly share code, notes, and snippets.

@bjurban
Created June 1, 2015 19:44
Show Gist options
  • Save bjurban/4e4b419694ba3ba045fe to your computer and use it in GitHub Desktop.
Save bjurban/4e4b419694ba3ba045fe to your computer and use it in GitHub Desktop.
lattice alternating axis tick marks
# alternating axis tick marks
# Bryan Urban
# 2015-06-01
xscale.components.alt <- function(lim, by=5, ...){
ans <- xscale.components.default(lim, ...)
tck.at <- ans$bottom$ticks$at
tck.lab <- as.character(tck.at)
ind <- length(tck.at)
tck.major <- tck.at[seq(1, ind, by=by)]
major <- tck.at %in% tck.major
tck <- ifelse(major, 2, 1)
tck.lab[!major] <- ""
ans$bottom$labels$labels <- tck.lab
ans$bottom$ticks$tck <- tck
ans$bottom$labels$check.overlap = FALSE
ans
}
xyplot(mpg ~ hp, mtcars,
xlim=c(20, 560),
scales=list(x=list(at=seq(25,550, by=5))),
xscale.components = xscale.components.alt
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment