[R] Lattice graphics: minor tick marks and panel.axis() question(s)
Stephen Tucker
brown_emu at yahoo.com
Sun Feb 18 15:36:50 CET 2007
Hello,
I have been a long-time Traditional graphics user and now moving to
try Lattice graphics. At the moment I cannot figure out how to place
minor tick marks in a figure made with Lattice's xyplot(). In
Traditional graphics, after calling plot() I would make two calls to
axis().
>From the manuals and help documentation I learned that 'scales' takes
multiple 'at' arguments only if they apply to each of the different
panels, so I thought to call 'panel.axis' in my panel
function. However I have a few questions regarding this procedure:
1) the placement of the ticks is not where I expect,
2) I cannot seem to get tick marks to point outwards even when I
set the clipping parameter in trellis parameters to "off"
3) (for multiple panels) I cannot figure out how to specify "bottom"
or "top" in each panel such that they appear on the side that the
default routine places major tickmarks
I have included example code at the bottom of this message. I would
appreciate any help if these issues are intuitively obvious to an
experienced Lattice user. Thank you very much in advance!
Stephen Tucker [using Windows XP and R 2.4.0]
######### Example code #########
#+++++ Define example data +++++
# x = 0.1 to 10 uniformly spaced in lognormal(base10) scale
# y = log10(x) + random noise
# this is repeated for four groups: a,b,c,d
xpoints = c(rep(1:9,times=2)*10^rep(c(-1,0),each=9),10)
df = data.frame(x=rep(xpoints,times=4),
y = rep(log10(xpoints),times=4)+rep(rnorm(length(xpoints),0,0.2),times=4),
g = rep(rep(letters[1:4],each=length(xpoints)),times=4))
#+++++
#+++++ Set clipping parameter +++++
clip = trellis.par.get("clip")
clip$panel = "off"
trellis.par.set("clip",clip)
#+++++
#+++++ Define panel function +++++
# plot x,y points
# draw axis
myPanelFunction = function(x,y,...) {
xpoints = c(rep(1:9,times=2)*10^rep(c(-1,0),each=9),10)
panel.xyplot(x,y,...)
panel.axis("bottom",at=xpoints,labels=FALSE,
tck=-0.5) #cannot get positive values of tck to work
}
#+++++
#+++++ Call to xyplot() +++++
xyplot(y~x|g,data=df,
panel = myPanelFunction,
scales=list(x=list(log=TRUE,at=c(0.1,1,10),
labels=parse(text=paste("10^",-1:1)))),
index.cond=list(c(3,4,1,2)))
#+++++
____________________________________________________________________________________
The fish are biting.
More information about the R-help
mailing list