From 22b606fc293f554105610de175249842aee4a116 Mon Sep 17 00:00:00 2001 From: Jean-Olivier Irisson Date: Tue, 7 May 2013 13:31:15 +0200 Subject: [PATCH 1/7] Make theme_bw truly black and white And improve some alignment and sizes (ticks width matches panel border width etc.) --- R/theme-defaults.r | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/R/theme-defaults.r b/R/theme-defaults.r index 85d6e46122..0c0c92ea81 100644 --- a/R/theme-defaults.r +++ b/R/theme-defaults.r @@ -70,15 +70,16 @@ theme_bw <- function(base_size = 12, base_family = "") { # Starts with theme_grey and then modify some parts theme_grey(base_size = base_size, base_family = base_family) %+replace% theme( - axis.text = element_text(size = rel(0.8)), - axis.ticks = element_line(colour = "black"), - legend.key = element_rect(colour = "grey80"), + axis.text = element_text(colour = "black", size = rel(0.8)), + axis.ticks = element_line(colour = "black", size=0.25), + legend.key = element_rect(colour = "black", size=0.25), panel.background = element_rect(fill = "white", colour = NA), - panel.border = element_rect(fill = NA, colour = "grey50"), - panel.grid.major = element_line(colour = "grey90", size = 0.2), - panel.grid.minor = element_line(colour = "grey98", size = 0.5), - strip.background = element_rect(fill = "grey80", colour = "grey50"), - strip.background = element_rect(fill = "grey80", colour = "grey50") + panel.border = element_rect(fill = NA, colour = "black", size=0.5), + panel.grid.major = element_line(colour = "black", size = 0.05), + panel.grid.minor = element_line(colour = "black", size = 0.01), + strip.background = element_rect(fill = "black", colour = NA), + strip.text.x = element_text(colour = "white"), + strip.text.y = element_text(colour = "white", angle = -90) ) } From 5ed3c92e796053a27a71b4fea0aaa5d6823e9169 Mon Sep 17 00:00:00 2001 From: Jean-Olivier Irisson Date: Tue, 7 May 2013 13:32:27 +0200 Subject: [PATCH 2/7] Add theme_white Which is intended to give an aspect similar to theme_grey but with a white background. --- R/theme-defaults.r | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/R/theme-defaults.r b/R/theme-defaults.r index 0c0c92ea81..fcb499f0de 100644 --- a/R/theme-defaults.r +++ b/R/theme-defaults.r @@ -83,6 +83,27 @@ theme_bw <- function(base_size = 12, base_family = "") { ) } +#' A theme with white background. +#' +#' @param base_size base font size +#' @param base_family base font family +#' @export +theme_white <- function(base_size = 12, base_family = "") { + # Starts with theme_grey and then modify some parts + theme_grey(base_size = base_size, base_family = base_family) %+replace% + theme( + axis.ticks = element_line(colour = "grey50", size=0.25), + legend.key = element_rect(fill="white", colour = "grey50", size=0.25), + panel.background = element_rect(fill = "white", colour = NA), + panel.border = element_rect(fill = NA, colour = "grey50", size=0.5), + panel.grid.major = element_line(colour = "grey80", size=0.25), + panel.grid.minor = element_line(colour = "grey92", size = 0.125), + strip.background = element_rect(fill = "grey50", colour = NA), + strip.text.x = element_text(colour = "white"), + strip.text.y = element_text(colour = "white", angle = -90) + ) +} + #' A minimalistic theme with no background annotations. #' #' @param base_size base font size From 75545023e444a3cd8f34094a1bd97a4e883c0e90 Mon Sep 17 00:00:00 2001 From: Jean-Olivier Irisson Date: Thu, 27 Feb 2014 18:26:18 +0100 Subject: [PATCH 3/7] Do not overwrite theme_bw and change names --- NAMESPACE | 2 ++ R/theme-defaults.r | 28 +++++++++++++++++++++++++--- man/theme_bw.Rd | 4 ++-- man/theme_light.Rd | 16 ++++++++++++++++ man/theme_linedraw.Rd | 16 ++++++++++++++++ 5 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 man/theme_light.Rd create mode 100644 man/theme_linedraw.Rd diff --git a/NAMESPACE b/NAMESPACE index 58e9886c8f..98518992f0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -390,7 +390,9 @@ export(theme_classic) export(theme_get) export(theme_gray) export(theme_grey) +export(theme_light) export(theme_line) +export(theme_linedraw) export(theme_minimal) export(theme_rect) export(theme_segment) diff --git a/R/theme-defaults.r b/R/theme-defaults.r index fcb499f0de..2705a31f4d 100644 --- a/R/theme-defaults.r +++ b/R/theme-defaults.r @@ -61,12 +61,33 @@ theme_grey <- function(base_size = 12, base_family = "") { theme_gray <- theme_grey -#' A theme with white background and black gridlines. +#' A theme with white background and dark gridlines. #' #' @param base_size base font size #' @param base_family base font family #' @export theme_bw <- function(base_size = 12, base_family = "") { + # Starts with theme_grey and then modify some parts + theme_grey(base_size = base_size, base_family = base_family) %+replace% + theme( + axis.text = element_text(size = rel(0.8)), + axis.ticks = element_line(colour = "black"), + legend.key = element_rect(colour = "grey80"), + panel.background = element_rect(fill = "white", colour = NA), + panel.border = element_rect(fill = NA, colour = "grey50"), + panel.grid.major = element_line(colour = "grey90", size = 0.2), + panel.grid.minor = element_line(colour = "grey98", size = 0.5), + strip.background = element_rect(fill = "grey80", colour = "grey50"), + strip.background = element_rect(fill = "grey80", colour = "grey50") + ) +} + +#' A theme with white background and black gridlines. +#' +#' @param base_size base font size +#' @param base_family base font family +#' @export +theme_linedraw <- function(base_size = 12, base_family = "") { # Starts with theme_grey and then modify some parts theme_grey(base_size = base_size, base_family = base_family) %+replace% theme( @@ -83,12 +104,12 @@ theme_bw <- function(base_size = 12, base_family = "") { ) } -#' A theme with white background. +#' A theme with white background and light grey lines #' #' @param base_size base font size #' @param base_family base font family #' @export -theme_white <- function(base_size = 12, base_family = "") { +theme_light <- function(base_size = 12, base_family = "") { # Starts with theme_grey and then modify some parts theme_grey(base_size = base_size, base_family = base_family) %+replace% theme( @@ -102,6 +123,7 @@ theme_white <- function(base_size = 12, base_family = "") { strip.text.x = element_text(colour = "white"), strip.text.y = element_text(colour = "white", angle = -90) ) + } #' A minimalistic theme with no background annotations. diff --git a/man/theme_bw.Rd b/man/theme_bw.Rd index 99e8798f77..03ebb1cef7 100644 --- a/man/theme_bw.Rd +++ b/man/theme_bw.Rd @@ -1,7 +1,7 @@ % Generated by roxygen2 (4.0.0): do not edit by hand \name{theme_bw} \alias{theme_bw} -\title{A theme with white background and black gridlines.} +\title{A theme with white background and dark gridlines.} \usage{ theme_bw(base_size = 12, base_family = "") } @@ -11,6 +11,6 @@ theme_bw(base_size = 12, base_family = "") \item{base_family}{base font family} } \description{ -A theme with white background and black gridlines. +A theme with white background and dark gridlines. } diff --git a/man/theme_light.Rd b/man/theme_light.Rd new file mode 100644 index 0000000000..d423718681 --- /dev/null +++ b/man/theme_light.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2 (4.0.0): do not edit by hand +\name{theme_light} +\alias{theme_light} +\title{A theme with white background and light grey lines} +\usage{ +theme_light(base_size = 12, base_family = "") +} +\arguments{ + \item{base_size}{base font size} + + \item{base_family}{base font family} +} +\description{ +A theme with white background and light grey lines +} + diff --git a/man/theme_linedraw.Rd b/man/theme_linedraw.Rd new file mode 100644 index 0000000000..4c28fb370c --- /dev/null +++ b/man/theme_linedraw.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2 (4.0.0): do not edit by hand +\name{theme_linedraw} +\alias{theme_linedraw} +\title{A theme with white background and black gridlines.} +\usage{ +theme_linedraw(base_size = 12, base_family = "") +} +\arguments{ + \item{base_size}{base font size} + + \item{base_family}{base font family} +} +\description{ +A theme with white background and black gridlines. +} + From 456c9fda9b4a9febf80c261ed14fc2fcaf6da421 Mon Sep 17 00:00:00 2001 From: Jean-Olivier Irisson Date: Mon, 17 Mar 2014 12:39:42 +0100 Subject: [PATCH 4/7] Fix coding style for new themes Spaces around `=` --- R/theme-defaults.r | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/R/theme-defaults.r b/R/theme-defaults.r index 2705a31f4d..290f8c6c07 100644 --- a/R/theme-defaults.r +++ b/R/theme-defaults.r @@ -92,10 +92,10 @@ theme_linedraw <- function(base_size = 12, base_family = "") { theme_grey(base_size = base_size, base_family = base_family) %+replace% theme( axis.text = element_text(colour = "black", size = rel(0.8)), - axis.ticks = element_line(colour = "black", size=0.25), - legend.key = element_rect(colour = "black", size=0.25), + axis.ticks = element_line(colour = "black", size = 0.25), + legend.key = element_rect(colour = "black", size = 0.25), panel.background = element_rect(fill = "white", colour = NA), - panel.border = element_rect(fill = NA, colour = "black", size=0.5), + panel.border = element_rect(fill = NA, colour = "black", size = 0.5), panel.grid.major = element_line(colour = "black", size = 0.05), panel.grid.minor = element_line(colour = "black", size = 0.01), strip.background = element_rect(fill = "black", colour = NA), @@ -113,11 +113,11 @@ theme_light <- function(base_size = 12, base_family = "") { # Starts with theme_grey and then modify some parts theme_grey(base_size = base_size, base_family = base_family) %+replace% theme( - axis.ticks = element_line(colour = "grey50", size=0.25), - legend.key = element_rect(fill="white", colour = "grey50", size=0.25), + axis.ticks = element_line(colour = "grey50", size = 0.25), + legend.key = element_rect(fill = "white", colour = "grey50", size = 0.25), panel.background = element_rect(fill = "white", colour = NA), - panel.border = element_rect(fill = NA, colour = "grey50", size=0.5), - panel.grid.major = element_line(colour = "grey80", size=0.25), + panel.border = element_rect(fill = NA, colour = "grey50", size = 0.5), + panel.grid.major = element_line(colour = "grey80", size = 0.25), panel.grid.minor = element_line(colour = "grey92", size = 0.125), strip.background = element_rect(fill = "grey50", colour = NA), strip.text.x = element_text(colour = "white"), From 3f7fceb0a4cf3966f30d199949e0e8971b54614b Mon Sep 17 00:00:00 2001 From: Jean-Olivier Irisson Date: Mon, 17 Mar 2014 12:42:50 +0100 Subject: [PATCH 5/7] Link the documentation of all themes Using the `@family` keyword of roxygen --- R/theme-defaults.r | 6 ++++++ man/theme_bw.Rd | 6 ++++++ man/theme_classic.Rd | 6 ++++++ man/theme_grey.Rd | 5 +++++ man/theme_light.Rd | 6 ++++++ man/theme_linedraw.Rd | 6 ++++++ man/theme_minimal.Rd | 6 ++++++ 7 files changed, 41 insertions(+) diff --git a/R/theme-defaults.r b/R/theme-defaults.r index 290f8c6c07..94d5e53b5a 100644 --- a/R/theme-defaults.r +++ b/R/theme-defaults.r @@ -4,6 +4,7 @@ #' @param base_family base font family #' @aliases theme_gray theme_grey #' @export theme_gray theme_grey +#' @family themes theme_grey <- function(base_size = 12, base_family = "") { theme( # Elements in this first block aren't used directly, but are inherited @@ -66,6 +67,7 @@ theme_gray <- theme_grey #' @param base_size base font size #' @param base_family base font family #' @export +#' @family themes theme_bw <- function(base_size = 12, base_family = "") { # Starts with theme_grey and then modify some parts theme_grey(base_size = base_size, base_family = base_family) %+replace% @@ -87,6 +89,7 @@ theme_bw <- function(base_size = 12, base_family = "") { #' @param base_size base font size #' @param base_family base font family #' @export +#' @family themes theme_linedraw <- function(base_size = 12, base_family = "") { # Starts with theme_grey and then modify some parts theme_grey(base_size = base_size, base_family = base_family) %+replace% @@ -109,6 +112,7 @@ theme_linedraw <- function(base_size = 12, base_family = "") { #' @param base_size base font size #' @param base_family base font family #' @export +#' @family themes theme_light <- function(base_size = 12, base_family = "") { # Starts with theme_grey and then modify some parts theme_grey(base_size = base_size, base_family = base_family) %+replace% @@ -131,6 +135,7 @@ theme_light <- function(base_size = 12, base_family = "") { #' @param base_size base font size #' @param base_family base font family #' @export +#' @family themes theme_minimal <- function(base_size = 12, base_family = "") { # Starts with theme_bw and then modify some parts theme_bw(base_size = base_size, base_family = base_family) %+replace% @@ -149,6 +154,7 @@ theme_minimal <- function(base_size = 12, base_family = "") { #' @param base_size base font size #' @param base_family base font family #' @export +#' @family themes theme_classic <- function(base_size = 12, base_family = ""){ theme_bw(base_size = base_size, base_family = base_family) %+replace% theme( diff --git a/man/theme_bw.Rd b/man/theme_bw.Rd index 03ebb1cef7..7df1d61704 100644 --- a/man/theme_bw.Rd +++ b/man/theme_bw.Rd @@ -13,4 +13,10 @@ theme_bw(base_size = 12, base_family = "") \description{ A theme with white background and dark gridlines. } +\seealso{ +Other themes: \code{\link{theme_classic}}; + \code{\link{theme_gray}}, \code{\link{theme_grey}}; + \code{\link{theme_light}}; \code{\link{theme_linedraw}}; + \code{\link{theme_minimal}} +} diff --git a/man/theme_classic.Rd b/man/theme_classic.Rd index 1bb8147832..76f0f25b0d 100644 --- a/man/theme_classic.Rd +++ b/man/theme_classic.Rd @@ -13,4 +13,10 @@ theme_classic(base_size = 12, base_family = "") \description{ A classic-looking theme, with x and y axis lines and no gridlines. } +\seealso{ +Other themes: \code{\link{theme_bw}}; + \code{\link{theme_gray}}, \code{\link{theme_grey}}; + \code{\link{theme_light}}; \code{\link{theme_linedraw}}; + \code{\link{theme_minimal}} +} diff --git a/man/theme_grey.Rd b/man/theme_grey.Rd index 52bdffa5d6..2374a14b8b 100644 --- a/man/theme_grey.Rd +++ b/man/theme_grey.Rd @@ -14,4 +14,9 @@ theme_grey(base_size = 12, base_family = "") \description{ A theme with grey background and white gridlines. } +\seealso{ +Other themes: \code{\link{theme_bw}}; + \code{\link{theme_classic}}; \code{\link{theme_light}}; + \code{\link{theme_linedraw}}; \code{\link{theme_minimal}} +} diff --git a/man/theme_light.Rd b/man/theme_light.Rd index d423718681..393d99f73c 100644 --- a/man/theme_light.Rd +++ b/man/theme_light.Rd @@ -13,4 +13,10 @@ theme_light(base_size = 12, base_family = "") \description{ A theme with white background and light grey lines } +\seealso{ +Other themes: \code{\link{theme_bw}}; + \code{\link{theme_classic}}; \code{\link{theme_gray}}, + \code{\link{theme_grey}}; \code{\link{theme_linedraw}}; + \code{\link{theme_minimal}} +} diff --git a/man/theme_linedraw.Rd b/man/theme_linedraw.Rd index 4c28fb370c..0adeaba1ac 100644 --- a/man/theme_linedraw.Rd +++ b/man/theme_linedraw.Rd @@ -13,4 +13,10 @@ theme_linedraw(base_size = 12, base_family = "") \description{ A theme with white background and black gridlines. } +\seealso{ +Other themes: \code{\link{theme_bw}}; + \code{\link{theme_classic}}; \code{\link{theme_gray}}, + \code{\link{theme_grey}}; \code{\link{theme_light}}; + \code{\link{theme_minimal}} +} diff --git a/man/theme_minimal.Rd b/man/theme_minimal.Rd index 0f1eb59051..be91e893cf 100644 --- a/man/theme_minimal.Rd +++ b/man/theme_minimal.Rd @@ -13,4 +13,10 @@ theme_minimal(base_size = 12, base_family = "") \description{ A minimalistic theme with no background annotations. } +\seealso{ +Other themes: \code{\link{theme_bw}}; + \code{\link{theme_classic}}; \code{\link{theme_gray}}, + \code{\link{theme_grey}}; \code{\link{theme_light}}; + \code{\link{theme_linedraw}} +} From 780887511fd021e456590cde292582b1ed3eea46 Mon Sep 17 00:00:00 2001 From: Jean-Olivier Irisson Date: Mon, 17 Mar 2014 12:50:37 +0100 Subject: [PATCH 6/7] Add examples to showcase themes --- R/theme-defaults.r | 18 ++++++++++++++++++ man/theme_light.Rd | 10 ++++++++++ man/theme_linedraw.Rd | 10 ++++++++++ 3 files changed, 38 insertions(+) diff --git a/R/theme-defaults.r b/R/theme-defaults.r index 94d5e53b5a..0d0a0d1f11 100644 --- a/R/theme-defaults.r +++ b/R/theme-defaults.r @@ -90,6 +90,15 @@ theme_bw <- function(base_size = 12, base_family = "") { #' @param base_family base font family #' @export #' @family themes +#' @examples +#' p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg)) +#' p +#' # 'classic' dark-on-light theme +#' p + theme_bw() +#' # this theme +#' p + theme_linedraw() +#' # variation with light box and axes legends +#' p + theme_light() theme_linedraw <- function(base_size = 12, base_family = "") { # Starts with theme_grey and then modify some parts theme_grey(base_size = base_size, base_family = base_family) %+replace% @@ -113,6 +122,15 @@ theme_linedraw <- function(base_size = 12, base_family = "") { #' @param base_family base font family #' @export #' @family themes +#' @examples +#' p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg)) +#' p +#' # 'classic' dark-on-light theme +#' p + theme_bw() +#' # this theme +#' p + theme_light() +#' # variation with dark box and axes legends +#' p + theme_linedraw() theme_light <- function(base_size = 12, base_family = "") { # Starts with theme_grey and then modify some parts theme_grey(base_size = base_size, base_family = base_family) %+replace% diff --git a/man/theme_light.Rd b/man/theme_light.Rd index 393d99f73c..5415e290e2 100644 --- a/man/theme_light.Rd +++ b/man/theme_light.Rd @@ -13,6 +13,16 @@ theme_light(base_size = 12, base_family = "") \description{ A theme with white background and light grey lines } +\examples{ +p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg)) +p +# 'classic' dark-on-light theme +p + theme_bw() +# this theme +p + theme_light() +# variation with dark box and axes legends +p + theme_linedraw() +} \seealso{ Other themes: \code{\link{theme_bw}}; \code{\link{theme_classic}}; \code{\link{theme_gray}}, diff --git a/man/theme_linedraw.Rd b/man/theme_linedraw.Rd index 0adeaba1ac..355daae5d4 100644 --- a/man/theme_linedraw.Rd +++ b/man/theme_linedraw.Rd @@ -13,6 +13,16 @@ theme_linedraw(base_size = 12, base_family = "") \description{ A theme with white background and black gridlines. } +\examples{ +p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg)) +p +# 'classic' dark-on-light theme +p + theme_bw() +# this theme +p + theme_linedraw() +# variation with light box and axes legends +p + theme_light() +} \seealso{ Other themes: \code{\link{theme_bw}}; \code{\link{theme_classic}}; \code{\link{theme_gray}}, From f78e49e3e3a0b5c0eec80ba9f16810b9cf47ca17 Mon Sep 17 00:00:00 2001 From: Jean-Olivier Irisson Date: Mon, 17 Mar 2014 12:52:00 +0100 Subject: [PATCH 7/7] Add NEWS bit about new themes --- NEWS | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS b/NEWS index 83719560d7..fe900620be 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,11 @@ ggplot2 0.9.3.1.99 ---------------------------------------------------------------- +* Add new themes: `theme_linedraw()` is similar to `theme_bw()` but with + truly only white and black elements and spacing between elements identical + to `theme_gray`. `theme_light` is similar but with light gray box and axes + around the plot, to emphasise content more (@jiho, #923) + * Allow specifying only one of the limits in a scale and use the automatic calculation of the other limit by passing NA to to the limit function, `xlim()` or `ylim()` (@jimhester, #557).