Skip to content

Commit

Permalink
Set grid colour in panel.grid
Browse files Browse the repository at this point in the history
Fixes #2352
  • Loading branch information
hadley committed Nov 30, 2017
1 parent b699cd3 commit caca650
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Expand Up @@ -224,6 +224,10 @@ up correct aspect ratio, and draws a graticule.
* Complete themes now always override all elements of the default theme
(@has2k1, #2058, #2079)

* Themes now set default grid colour in `panel.grid` rather than individually
in `panel.grid.major` and `panel.grid.minor` individually. This makes it
slightly easier to customise the grid (#2352).

* Fixed bug when setting strips to `element_blank()` (@thomasp85).

* Axes positioned on the top and to the right can now customize their ticks and
Expand Down
23 changes: 13 additions & 10 deletions R/theme-defaults.r
Expand Up @@ -141,8 +141,8 @@ theme_grey <- function(base_size = 11, base_family = "",

panel.background = element_rect(fill = "grey92", colour = NA),
panel.border = element_blank(),
panel.grid.major = element_line(colour = "white"),
panel.grid.minor = element_line(colour = "white", size = rel(0.5)),
panel.grid = element_line(colour = "white"),
panel.grid.minor = element_line(size = rel(0.5)),
panel.spacing = unit(half_line, "pt"),
panel.spacing.x = NULL,
panel.spacing.y = NULL,
Expand Down Expand Up @@ -204,8 +204,8 @@ theme_bw <- function(base_size = 11, base_family = "",
panel.background = element_rect(fill = "white", colour = NA),
panel.border = element_rect(fill = NA, colour = "grey20"),
# make gridlines dark, same contrast with white as in theme_grey
panel.grid.major = element_line(colour = "grey92"),
panel.grid.minor = element_line(colour = "grey92", size = rel(0.5)),
panel.grid = element_line(colour = "grey92"),
panel.grid.minor = element_line(size = rel(0.5)),
# contour strips to match panel contour
strip.background = element_rect(fill = "grey85", colour = "grey20"),
# match legend key to background
Expand Down Expand Up @@ -239,8 +239,9 @@ theme_linedraw <- function(base_size = 11, base_family = "",

# pure black panel border and grid lines, but thinner
panel.border = element_rect(fill = NA, colour = "black", size = rel(1)),
panel.grid.major = element_line(colour = "black", size = rel(0.1)),
panel.grid.minor = element_line(colour = "black", size = rel(0.05)),
panel.grid = element_line(colour = "black"),
panel.grid.major = element_line(size = rel(0.1)),
panel.grid.minor = element_line(size = rel(0.05)),

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

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

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

0 comments on commit caca650

Please sign in to comment.