Skip to content

Commit caca650

Browse files
committed
Set grid colour in panel.grid
Fixes #2352
1 parent b699cd3 commit caca650

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ up correct aspect ratio, and draws a graticule.
224224
* Complete themes now always override all elements of the default theme
225225
(@has2k1, #2058, #2079)
226226

227+
* Themes now set default grid colour in `panel.grid` rather than individually
228+
in `panel.grid.major` and `panel.grid.minor` individually. This makes it
229+
slightly easier to customise the grid (#2352).
230+
227231
* Fixed bug when setting strips to `element_blank()` (@thomasp85).
228232

229233
* Axes positioned on the top and to the right can now customize their ticks and

R/theme-defaults.r

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ theme_grey <- function(base_size = 11, base_family = "",
141141

142142
panel.background = element_rect(fill = "grey92", colour = NA),
143143
panel.border = element_blank(),
144-
panel.grid.major = element_line(colour = "white"),
145-
panel.grid.minor = element_line(colour = "white", size = rel(0.5)),
144+
panel.grid = element_line(colour = "white"),
145+
panel.grid.minor = element_line(size = rel(0.5)),
146146
panel.spacing = unit(half_line, "pt"),
147147
panel.spacing.x = NULL,
148148
panel.spacing.y = NULL,
@@ -204,8 +204,8 @@ theme_bw <- function(base_size = 11, base_family = "",
204204
panel.background = element_rect(fill = "white", colour = NA),
205205
panel.border = element_rect(fill = NA, colour = "grey20"),
206206
# make gridlines dark, same contrast with white as in theme_grey
207-
panel.grid.major = element_line(colour = "grey92"),
208-
panel.grid.minor = element_line(colour = "grey92", size = rel(0.5)),
207+
panel.grid = element_line(colour = "grey92"),
208+
panel.grid.minor = element_line(size = rel(0.5)),
209209
# contour strips to match panel contour
210210
strip.background = element_rect(fill = "grey85", colour = "grey20"),
211211
# match legend key to background
@@ -239,8 +239,9 @@ theme_linedraw <- function(base_size = 11, base_family = "",
239239

240240
# pure black panel border and grid lines, but thinner
241241
panel.border = element_rect(fill = NA, colour = "black", size = rel(1)),
242-
panel.grid.major = element_line(colour = "black", size = rel(0.1)),
243-
panel.grid.minor = element_line(colour = "black", size = rel(0.05)),
242+
panel.grid = element_line(colour = "black"),
243+
panel.grid.major = element_line(size = rel(0.1)),
244+
panel.grid.minor = element_line(size = rel(0.05)),
244245

245246
# strips with black background and white text
246247
strip.background = element_rect(fill = "black"),
@@ -274,8 +275,9 @@ theme_light <- function(base_size = 11, base_family = "",
274275
panel.border = element_rect(fill = NA, colour = "grey70", size = rel(1)),
275276
# light grey, thinner gridlines
276277
# => make them slightly darker to keep acceptable contrast
277-
panel.grid.major = element_line(colour = "grey87", size = rel(0.5)),
278-
panel.grid.minor = element_line(colour = "grey87", size = rel(0.25)),
278+
panel.grid = element_line(colour = "grey87"),
279+
panel.grid.major = element_line(size = rel(0.5)),
280+
panel.grid.minor = element_line(size = rel(0.25)),
279281

280282
# match axes ticks thickness to gridlines and colour to panel border
281283
axis.ticks = element_line(colour = "grey70", size = rel(0.5)),
@@ -315,8 +317,9 @@ theme_dark <- function(base_size = 11, base_family = "",
315317
panel.background = element_rect(fill = "grey50", colour = NA),
316318
# inverse grid lines contrast compared to theme_grey
317319
# make them thinner and try to keep the same visual contrast as in theme_light
318-
panel.grid.major = element_line(colour = "grey42", size = rel(0.5)),
319-
panel.grid.minor = element_line(colour = "grey42", size = rel(0.25)),
320+
panel.grid = element_line(colour = "grey42"),
321+
panel.grid.major = element_line(size = rel(0.5)),
322+
panel.grid.minor = element_line(size = rel(0.25)),
320323

321324
# match axes ticks thickness to gridlines
322325
axis.ticks = element_line(colour = "grey20", size = rel(0.5)),

0 commit comments

Comments
 (0)