hadley/ggplot2 — Issue #275: Minor gridlines drawn underneath major gridlines
Author: zackw
Created: 2011-12-04 21:33:20+00:00
State: open

This is only the tip of the iceberg as far as optimizing the drawing commands generated by ggplot2, but this is the first thing that I've found that ggplot can directly control (most of the garbage is grid's fault).

The set of positions at which minor gridlines are drawn is a superset of the positions at which major gridlines are drawn. Since the major gridlines are drawn second, this has no effect on the *appearance* of the plot -- it just adds extra, unnecessary draw operations to vector-device output. As a blatant example, consider

pdf("t.pdf", colormodel="gray")
qplot(1, 1, geom="point")
dev.off()

The generated PDF draw commands include (some unrelated junk trimmed to make the problem clearer):

0.949 G 0.53 w
27.05 259.13 m 482.40 259.13 l S
254.72 28.67 m 254.72 489.60 l S
1.000 G 1.06 w
27.05 259.13 m 482.40 259.13 l S
254.72 28.67 m 254.72 489.60 l S

The first half of that is completely unnecessary.

I think fixing this would be as easy as having guide_grid() filter from x.minor and y.minor all entries that duplicated entries in x.major and y.major respectively.