Skip to content

New themes that do not overwrite existing ones #923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
70 changes: 69 additions & 1 deletion R/theme-defaults.r
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,11 +62,12 @@ 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
#' @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%
Expand All @@ -82,11 +84,76 @@ theme_bw <- function(base_size = 12, base_family = "") {
)
}

#' A theme with white background and black gridlines.
#'
#' @param base_size base font size
#' @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%
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),
panel.background = element_rect(fill = "white", colour = NA),
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)
)
}

#' A theme with white background and light grey lines
#'
#' @param base_size base font size
#' @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%
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
#' @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%
Expand All @@ -105,6 +172,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(
Expand Down
10 changes: 8 additions & 2 deletions man/theme_bw.Rd
Original file line number Diff line number Diff line change
@@ -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 = "")
}
Expand All @@ -11,6 +11,12 @@ 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.
}
\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}}
}

6 changes: 6 additions & 0 deletions man/theme_classic.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}

5 changes: 5 additions & 0 deletions man/theme_grey.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}

32 changes: 32 additions & 0 deletions man/theme_light.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
% 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
}
\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}},
\code{\link{theme_grey}}; \code{\link{theme_linedraw}};
\code{\link{theme_minimal}}
}

32 changes: 32 additions & 0 deletions man/theme_linedraw.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
% 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.
}
\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}},
\code{\link{theme_grey}}; \code{\link{theme_light}};
\code{\link{theme_minimal}}
}

6 changes: 6 additions & 0 deletions man/theme_minimal.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}