forked from tidyverse/ggplot2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguides-grid.r
30 lines (28 loc) · 1.04 KB
/
guides-grid.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Produce a grob to be used as for panel backgrounds
guide_grid <- function(theme, x.minor, x.major, y.minor, y.major) {
x.minor <- setdiff(x.minor, x.major)
y.minor <- setdiff(y.minor, y.major)
ggname("grill", grobTree(
element_render(theme, "panel.background"),
if (length(y.minor) > 0) element_render(
theme, "panel.grid.minor.y",
x = rep(0:1, length(y.minor)), y = rep(y.minor, each = 2),
id.lengths = rep(2, length(y.minor))
),
if (length(x.minor) > 0) element_render(
theme, "panel.grid.minor.x",
x = rep(x.minor, each = 2), y = rep(0:1, length(x.minor)),
id.lengths = rep(2, length(x.minor))
),
if (length(y.major) > 0) element_render(
theme, "panel.grid.major.y",
x = rep(0:1, length(y.major)), y = rep(y.major, each = 2),
id.lengths = rep(2, length(y.major))
),
if (length(x.major) > 0) element_render(
theme, "panel.grid.major.x",
x = rep(x.major, each = 2), y = rep(0:1, length(x.major)),
id.lengths = rep(2, length(x.major))
)
))
}