[R] How to insert gridlines in lattice density plot

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Apr 23 17:41:55 CEST 2010

On Thu, Apr 22, 2010 at 3:16 PM, Giles <gilescrane at verizon.net> wrote:
> Thank you Burt Gunter and David Winsemius,
> I confirmed David's comment.
> One must use type=c("p","g")
> in order to get both the grid and points.
> So, to use densityplot well,
> we must be quite aware of the options
> for panel.xyplot!

Actually, this works not by design, but due to the specifics of the
implementation. For example, you get no grid with

densityplot(rnorm(100), type = c("p", "g"), plot.points=FALSE)

One should not really be afraid of writing panel functions. All this
type= stuff is convenient, but in the end it's just syntactic sugar;
in the original Trellis design you could barely do anything beyond the
very basics without panel functions. It should not be conceptually
that big a leap to write

            panel = function(...) {
                panel.grid(h = 0, v = -1)

especially as doing so gives you greater control.


More information about the R-help mailing list