Re: [R] minor axis ticks in trellis graphics?
Dear Martin, Mea culpa! I screwed up. I was answering (not well, at that) a different question and somehow managed to make it a response to your request. Here's what may be a solution to your problem. (see also this post by ilai: https://stat.ethz.ch/pipermail/r-help/attachments/20120718/7133b673/attachment.pl) We define appropriate locations for the x-ticks to go with suitably defined labels and corresponding tick lengths. ## data: d - data.frame(x = 1:11, y = rnorm(11)) ## Where to put ticks and labels myat - 1:11 mylab - head(c(rbind(LETTERS[1:6], )), -1) # putting letters at every second tick ## lengths of ticks mytck - head(c(rbind(rep(1,6), .5)), -1) ## myat, mylab, mytck should all be same length ## plot xyplot(y ~ x, data = d, xlab=, scales = list(x = list( at = myat, labels = mylab)), par.settings = list( axis.components = list( bottom = list(tck = mytck ## Try it with different myat etc to see how it works myat - seq(1, 11, by = 2/3) mylab - head(c(rbind(LETTERS[1:6], , )), -2) mytck - head(c(rbind(rep(2,6), .5, .5)), -2) myat - seq(1, 11, by = 1/2) mylab - head(c(rbind(LETTERS[1:6], , , )), -3) mytck - head(c(rbind(rep(2,6), .5, 1, .5)), -3) The trick is in constructing suitable vectors myat, mylab, and mytck which you can do any way you like but I would check that the lengths are equal (recycling works fine for simple cases but always seems to trip me up in more complicated cases). Peter Ehlers On 2012-07-26 07:02, Martin Ivanov wrote: Dear Peter, Thank You very much for your suggestion. However, it seems to me to make a completely new notation to the x axis. While I just need to add minor ticks to the axis, that is smaller ticks inbetween the basic ticks. The other option would be to say which ticks to be small and which big, but I have no idea how. Any suggestions will be appreciated. Best regards, Martin embarassing junk from P. Ehlers cut __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] minor axis ticks in trellis graphics?
On 2012-07-13 01:05, Martin Ivanov wrote: Dear R users, I need to add minor axis ticks to my graph. In traditional R this is easily achievable by simply adding a second axis with the minor ticks. But how to do that in trellis? I am already out of ideas. Any suggestions will be appreciated. Haven't seen a response yet, so I'll give it a shot, sure to be replaced by something much simpler by Deepayan when he finds the time. Here are two ways: 1. Assign appropriate values to the elements of the xscale.components list. I prefer this. ## make some data d - data.frame(x = 1:12, y = rnorm(12)) at.ticks - c(4,8) at.labels - c(2,6,10) the_labels - letters[1:3] library(lattice) ## define a function to modify the xscale components; ## this function will be used inside xyplot(). myxscale.components - function(...) { ans - xscale.components.default(...) ans$bottom$ticks$at - at.ticks ans$bottom$labels$at - at.labels ans$bottom$labels$labels - the_labels ans } ## do the plot xyplot(y ~ x, data = d, scales = list(tck = c(1,0)), xscale.components = myxscale.components) You can put the modifying function inside the xyplot call. See ?axis.components. 2. This is more like the base graphics way. We create the plot without the x-axis and then use the trellis.focus/unfocus functions in conjunction with the panel.axis() function. See ?panel.axis for details. Here's the function to apply after the xyplot call: myfocus - function(){ trellis.focus(panel, 1, 1, clip.off = TRUE, highlight = FALSE) ## put the ticks in panel.axis(side = bottom, at = at.ticks, labels = FALSE, ticks = TRUE, tck = 1, outside = TRUE ) ## put the labels in panel.axis(side = bottom, at = at.labels, labels = the_labels, ticks = FALSE, tck = 0, outside = TRUE, rot = 0 # optional; try it without ) trellis.unfocus() } xyplot(y ~ x, data = d, scales = list( y = list(tck = c(1,0)), x = list(tck = c(0,0), at = 1, label = # to give us some bottom space ))) ## Now add the axis ticks and labels myfocus() Peter Ehlers Best regards, Martin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.