Skip to content

Commit 188c8e0

Browse files
committed
Merge pull request #923 from jiho/fix/theme_bw
New themes that do not overwrite existing ones
2 parents 276780a + f78e49e commit 188c8e0

9 files changed

+165
-3
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ export(theme_classic)
391391
export(theme_get)
392392
export(theme_gray)
393393
export(theme_grey)
394+
export(theme_light)
394395
export(theme_line)
396+
export(theme_linedraw)
395397
export(theme_minimal)
396398
export(theme_rect)
397399
export(theme_segment)

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ ggplot2 0.9.3.1.99
33
* `stat_ellipse()` adds data ellipses. It supports bivariate normal and t distributions,
44
as well as a euclidian distance circle. (@jofrhwld, #926)
55

6+
* Add new themes: `theme_linedraw()` is similar to `theme_bw()` but with
7+
truly only white and black elements and spacing between elements identical
8+
to `theme_gray`. `theme_light` is similar but with light gray box and axes
9+
around the plot, to emphasise content more (@jiho, #923)
10+
611
* Allow specifying only one of the limits in a scale and use the automatic
712
calculation of the other limit by passing NA to to the limit function,
813
`xlim()` or `ylim()` (@jimhester, #557).

R/theme-defaults.r

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#' @param base_family base font family
55
#' @aliases theme_gray theme_grey
66
#' @export theme_gray theme_grey
7+
#' @family themes
78
theme_grey <- function(base_size = 12, base_family = "") {
89
theme(
910
# Elements in this first block aren't used directly, but are inherited
@@ -61,11 +62,12 @@ theme_grey <- function(base_size = 12, base_family = "") {
6162
theme_gray <- theme_grey
6263

6364

64-
#' A theme with white background and black gridlines.
65+
#' A theme with white background and dark gridlines.
6566
#'
6667
#' @param base_size base font size
6768
#' @param base_family base font family
6869
#' @export
70+
#' @family themes
6971
theme_bw <- function(base_size = 12, base_family = "") {
7072
# Starts with theme_grey and then modify some parts
7173
theme_grey(base_size = base_size, base_family = base_family) %+replace%
@@ -82,11 +84,76 @@ theme_bw <- function(base_size = 12, base_family = "") {
8284
)
8385
}
8486

87+
#' A theme with white background and black gridlines.
88+
#'
89+
#' @param base_size base font size
90+
#' @param base_family base font family
91+
#' @export
92+
#' @family themes
93+
#' @examples
94+
#' p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg))
95+
#' p
96+
#' # 'classic' dark-on-light theme
97+
#' p + theme_bw()
98+
#' # this theme
99+
#' p + theme_linedraw()
100+
#' # variation with light box and axes legends
101+
#' p + theme_light()
102+
theme_linedraw <- function(base_size = 12, base_family = "") {
103+
# Starts with theme_grey and then modify some parts
104+
theme_grey(base_size = base_size, base_family = base_family) %+replace%
105+
theme(
106+
axis.text = element_text(colour = "black", size = rel(0.8)),
107+
axis.ticks = element_line(colour = "black", size = 0.25),
108+
legend.key = element_rect(colour = "black", size = 0.25),
109+
panel.background = element_rect(fill = "white", colour = NA),
110+
panel.border = element_rect(fill = NA, colour = "black", size = 0.5),
111+
panel.grid.major = element_line(colour = "black", size = 0.05),
112+
panel.grid.minor = element_line(colour = "black", size = 0.01),
113+
strip.background = element_rect(fill = "black", colour = NA),
114+
strip.text.x = element_text(colour = "white"),
115+
strip.text.y = element_text(colour = "white", angle = -90)
116+
)
117+
}
118+
119+
#' A theme with white background and light grey lines
120+
#'
121+
#' @param base_size base font size
122+
#' @param base_family base font family
123+
#' @export
124+
#' @family themes
125+
#' @examples
126+
#' p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg))
127+
#' p
128+
#' # 'classic' dark-on-light theme
129+
#' p + theme_bw()
130+
#' # this theme
131+
#' p + theme_light()
132+
#' # variation with dark box and axes legends
133+
#' p + theme_linedraw()
134+
theme_light <- function(base_size = 12, base_family = "") {
135+
# Starts with theme_grey and then modify some parts
136+
theme_grey(base_size = base_size, base_family = base_family) %+replace%
137+
theme(
138+
axis.ticks = element_line(colour = "grey50", size = 0.25),
139+
legend.key = element_rect(fill = "white", colour = "grey50", size = 0.25),
140+
panel.background = element_rect(fill = "white", colour = NA),
141+
panel.border = element_rect(fill = NA, colour = "grey50", size = 0.5),
142+
panel.grid.major = element_line(colour = "grey80", size = 0.25),
143+
panel.grid.minor = element_line(colour = "grey92", size = 0.125),
144+
strip.background = element_rect(fill = "grey50", colour = NA),
145+
strip.text.x = element_text(colour = "white"),
146+
strip.text.y = element_text(colour = "white", angle = -90)
147+
)
148+
149+
}
150+
85151
#' A minimalistic theme with no background annotations.
86152
#'
87153
#' @param base_size base font size
88154
#' @param base_family base font family
89155
#' @export
156+
#' @family themes
90157
theme_minimal <- function(base_size = 12, base_family = "") {
91158
# Starts with theme_bw and then modify some parts
92159
theme_bw(base_size = base_size, base_family = base_family) %+replace%
@@ -105,6 +172,7 @@ theme_minimal <- function(base_size = 12, base_family = "") {
105172
#' @param base_size base font size
106173
#' @param base_family base font family
107174
#' @export
175+
#' @family themes
108176
theme_classic <- function(base_size = 12, base_family = ""){
109177
theme_bw(base_size = base_size, base_family = base_family) %+replace%
110178
theme(

man/theme_bw.Rd

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Generated by roxygen2 (4.0.0): do not edit by hand
22
\name{theme_bw}
33
\alias{theme_bw}
4-
\title{A theme with white background and black gridlines.}
4+
\title{A theme with white background and dark gridlines.}
55
\usage{
66
theme_bw(base_size = 12, base_family = "")
77
}
@@ -11,6 +11,12 @@ theme_bw(base_size = 12, base_family = "")
1111
\item{base_family}{base font family}
1212
}
1313
\description{
14-
A theme with white background and black gridlines.
14+
A theme with white background and dark gridlines.
15+
}
16+
\seealso{
17+
Other themes: \code{\link{theme_classic}};
18+
\code{\link{theme_gray}}, \code{\link{theme_grey}};
19+
\code{\link{theme_light}}; \code{\link{theme_linedraw}};
20+
\code{\link{theme_minimal}}
1521
}
1622

man/theme_classic.Rd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ theme_classic(base_size = 12, base_family = "")
1313
\description{
1414
A classic-looking theme, with x and y axis lines and no gridlines.
1515
}
16+
\seealso{
17+
Other themes: \code{\link{theme_bw}};
18+
\code{\link{theme_gray}}, \code{\link{theme_grey}};
19+
\code{\link{theme_light}}; \code{\link{theme_linedraw}};
20+
\code{\link{theme_minimal}}
21+
}
1622

man/theme_grey.Rd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ theme_grey(base_size = 12, base_family = "")
1414
\description{
1515
A theme with grey background and white gridlines.
1616
}
17+
\seealso{
18+
Other themes: \code{\link{theme_bw}};
19+
\code{\link{theme_classic}}; \code{\link{theme_light}};
20+
\code{\link{theme_linedraw}}; \code{\link{theme_minimal}}
21+
}
1722

man/theme_light.Rd

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
% Generated by roxygen2 (4.0.0): do not edit by hand
2+
\name{theme_light}
3+
\alias{theme_light}
4+
\title{A theme with white background and light grey lines}
5+
\usage{
6+
theme_light(base_size = 12, base_family = "")
7+
}
8+
\arguments{
9+
\item{base_size}{base font size}
10+
11+
\item{base_family}{base font family}
12+
}
13+
\description{
14+
A theme with white background and light grey lines
15+
}
16+
\examples{
17+
p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg))
18+
p
19+
# 'classic' dark-on-light theme
20+
p + theme_bw()
21+
# this theme
22+
p + theme_light()
23+
# variation with dark box and axes legends
24+
p + theme_linedraw()
25+
}
26+
\seealso{
27+
Other themes: \code{\link{theme_bw}};
28+
\code{\link{theme_classic}}; \code{\link{theme_gray}},
29+
\code{\link{theme_grey}}; \code{\link{theme_linedraw}};
30+
\code{\link{theme_minimal}}
31+
}
32+

man/theme_linedraw.Rd

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
% Generated by roxygen2 (4.0.0): do not edit by hand
2+
\name{theme_linedraw}
3+
\alias{theme_linedraw}
4+
\title{A theme with white background and black gridlines.}
5+
\usage{
6+
theme_linedraw(base_size = 12, base_family = "")
7+
}
8+
\arguments{
9+
\item{base_size}{base font size}
10+
11+
\item{base_family}{base font family}
12+
}
13+
\description{
14+
A theme with white background and black gridlines.
15+
}
16+
\examples{
17+
p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg))
18+
p
19+
# 'classic' dark-on-light theme
20+
p + theme_bw()
21+
# this theme
22+
p + theme_linedraw()
23+
# variation with light box and axes legends
24+
p + theme_light()
25+
}
26+
\seealso{
27+
Other themes: \code{\link{theme_bw}};
28+
\code{\link{theme_classic}}; \code{\link{theme_gray}},
29+
\code{\link{theme_grey}}; \code{\link{theme_light}};
30+
\code{\link{theme_minimal}}
31+
}
32+

man/theme_minimal.Rd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ theme_minimal(base_size = 12, base_family = "")
1313
\description{
1414
A minimalistic theme with no background annotations.
1515
}
16+
\seealso{
17+
Other themes: \code{\link{theme_bw}};
18+
\code{\link{theme_classic}}; \code{\link{theme_gray}},
19+
\code{\link{theme_grey}}; \code{\link{theme_light}};
20+
\code{\link{theme_linedraw}}
21+
}
1622

0 commit comments

Comments
 (0)