Skip to content

Finer panel grid lines #577

@grantmcdermott

Description

@grantmcdermott

Originally raised by @zeileis here: #409 (comment)

Also, can we easily set a strategy to obtain the finer grid (with one extra grid step in between the ticks)? I actually do like that better than the rather coarse grid that we get in tinyplot.

We need to think about both the 1) user interface and 2) internal logic.

  1. For the user-facing interface, I quite like the grid = "xy" vs grid = "XY" input logic that Bob Rudis uses in his hrbrthemes package. The only difference is that I wouldn't worry about combination variants, e.g., "xXY". I would just stick to <lower case> => fine grid, while <upper case> => regular grid (where the latter is equivalent to our current grid = TRUE default). Similarly, I wouldn't worry about different tickness for the minor grid elements. Just keep everything the same.

  2. For internal implementation, we would need to edit the panel grid logic of facet.R, so that it captures these finer grid cases and calculates the appropriate (halved) break points. Something like this as a manual example:

library(tinyplot)
tinytheme("clean2", grid = FALSE)

plt(wt ~ mpg | factor(cyl), mtcars)

xaxbs = 5/2; xlim = par('usr')[1:2]
yaxbs = 1/2; ylim = par('usr')[3:4]

abline(
  v = seq(floor(xlim[1] / xaxbs) * xaxbs, ceiling(xlim[2] / xaxbs) * xaxbs, xaxbs),
  col = tpar('grid.col'), lwd = tpar('grid.lwd'), lty = tpar('lty')
)
abline(
  h = seq(floor(ylim[1] / yaxbs) * yaxbs, ceiling(ylim[2] / yaxbs) * yaxbs, yaxbs),
  col = tpar('grid.col'), lwd = tpar('grid.lwd'), lty = tpar('lty')
)

Created on 2026-05-07 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions