I'm trying to produce a plot with lattice's xyplot by the following code:
set.seed(123) #### make it reproducible
df<-data.frame(x=runif(100,1,1e7),y=runif(100,0.01,.08),t=as.factor(sample(1:3,100,replace=T)))
png("xyplot_grid_misaligned.png",800,800)
p<-xyplot(y ~ x,groups=t,data=df,scales=list(x=list(log=10,equispaced.log=F)),auto.key=T,ylim=c(-.01,.1),grid=T)
print(p)
dev.off()
It produces, as expected, a beautiful plot:
I'd like the grid on the plot to be aligned with the tick marks generated by equispaced.log=F
. The documentation of xyplot only discusses grid
in relation to multiple plots, as do some other threads in SO and other sites (In fact, I got the grid=T
argumment from another site: Using Lattice graphics in R, and even there you can see that when equispaced.log=F
is used, the grid "misaligns" with the ticks).
Just in case someone might think this is a duplicate of SO: aligning-grid-lines-to-axis-ticks-in-lattice-graphics, please notice that the question in there was how to align the grids in a multiplot (and, at the time, the thread has no answer yet).
How can I have xyplot "aligning" grid lines to x ticks while using equispaced.log=F
?
Thanks!