I have a Lattice plot in which I want to adjust the number of tick marks used, and I want to have the drawn grid reflect that change. Here is what I'm doing: bwplot(var1 ~ var2, data=df, scales=list(tick.number=10), panel=function(...) { panel.grid(h=0,v=-1,...); panel.stripplot(col="gray40", pch="|", cex=2, ...); panel.bwplot(...); }) Unfortunately this doesn't quite work. Although the bwplot's tick marks are indeed increased as requested, the panel.grid produces the same (3 line) grid as before, seemingly unaware of the changed # of ticks. Any suggestions on how to achieve what I want?
Berton Gunter
2005-Jun-14 23:12 UTC
[R] lattice, panel.grid, and scales=list(tick.number=XXX)
If you look at the code of panel.grid, you'll see why it doesn't work -- it does not use any of the scale parameters. Moreover the Help page for panel.grid explicitly warns that the h,v=-1 specification may not work, so no promises have been broken. I'm not sure how bwplot handles grids, since one of the axes is determined by the number of groups and not the range of the data as in xyplot. You might try specifying the at= argument for both the scales list and at the top level call for panel.grid to pick up. i.e. bwplot( ..., scales = list (at = where tic marks go),at= where tic marks go, ...). Alternatively, wait for Deepayan to give a definitive answer. -- Bert Gunter -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of M. K. Sent: Tuesday, June 14, 2005 3:37 PM To: R-help mailing list Subject: [R] lattice, panel.grid, and scales=list(tick.number=XXX) I have a Lattice plot in which I want to adjust the number of tick marks used, and I want to have the drawn grid reflect that change. Here is what I'm doing: bwplot(var1 ~ var2, data=df, scales=list(tick.number=10), panel=function(...) { panel.grid(h=0,v=-1,...); panel.stripplot(col="gray40", pch="|", cex=2, ...); panel.bwplot(...); }) Unfortunately this doesn't quite work. Although the bwplot's tick marks are indeed increased as requested, the panel.grid produces the same (3 line) grid as before, seemingly unaware of the changed # of ticks. Any suggestions on how to achieve what I want? ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Deepayan Sarkar
2005-Jun-17 11:54 UTC
[R] Fwd: lattice, panel.grid, and scales=list(tick.number=XXX)
I just realised that I had forgotten to copy this to the list. ---------- Forwarded message ---------- From: Deepayan Sarkar <deepayan.sarkar at gmail.com> Date: Jun 15, 2005 12:13 PM Subject: Re: [R] lattice, panel.grid, and scales=list(tick.number=XXX) To: Berton Gunter <gunter.berton at gene.com> On 6/14/05, Berton Gunter <gunter.berton at gene.com> wrote:> If you look at the code of panel.grid, you'll see why it doesn't work -- it > does not use any of the scale parameters. Moreover the Help page for > panel.grid explicitly warns that the h,v=-1 specification may not work, so > no promises have been broken.Right, the determination of tick mark locations can be arbitrarily complicated, via the use of methods of the (unexported) generic 'formattedTicksAndLabels'. The only way I can think of to make panel.grid aware of that is to store the results of that computation somewhere. Note that these results could potentially be different for every panel. While this is not impossible, it violates the principle that a panel function only has access to the data for that panel (not that this isn't ever violated, but not to this extent), and I would be inclined to keep things as they are unless there are better reasons. In this particular case, the tick computations are simple, so one could do (using the recently added 'current.panel.limits', only available if you update lattice to the latest version): bwplot(voice.part ~ height, data=singer, scales = list(tick.number = 10), panel = function(...) { ref.line <- trellis.par.get("reference.line") panel.abline(v = pretty(current.panel.limits()$xlim, n = 10), col = ref.line$col, lty = ref.line$lty, lwd = ref.line$lwd) panel.bwplot(...) }) [...]> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of M. K. > Sent: Tuesday, June 14, 2005 3:37 PM > To: R-help mailing list > Subject: [R] lattice, panel.grid, and scales=list(tick.number=XXX) > > I have a Lattice plot in which I want to adjust the number of tick > marks used, and I want to have the drawn grid reflect that change. > Here is what I'm doing: > > bwplot(var1 ~ var2, data=df, scales=list(tick.number=10), > panel=function(...) { > panel.grid(h=0,v=-1,...); > panel.stripplot(col="gray40", pch="|", cex=2, ...); > panel.bwplot(...); > }) > > Unfortunately this doesn't quite work. Although the bwplot's tick > marks are indeed increased as requested, the panel.grid produces the > same (3 line) grid as before, seemingly unaware of the changed # of > ticks.