diff --git a/NEWS.md b/NEWS.md
index f517486bc2..cc9f160110 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,9 @@
# ggplot2 2.2.1.9000
+* Theme functions now have the optional parameters `base_line_size` and
+ `base_rect_size` to control the default sizes of line and rectangle elements
+ (@karawoo, #2176).
+
* Fixed bug in `coord_polar` that prevented secondary axis ticks and labels
from being drawn (@dylan-stark, #2072)
diff --git a/R/theme-defaults.r b/R/theme-defaults.r
index 7dae481723..acd0ac3940 100644
--- a/R/theme-defaults.r
+++ b/R/theme-defaults.r
@@ -6,6 +6,8 @@
#'
#' @param base_size base font size
#' @param base_family base font family
+#' @param base_line_size base size for line elements
+#' @param base_rect_size base size for rect elements
#'
#' @details
#' \describe{
@@ -64,16 +66,22 @@ NULL
#' @include theme.r
#' @export
#' @rdname ggtheme
-theme_grey <- function(base_size = 11, base_family = "") {
+theme_grey <- function(base_size = 11, base_family = "",
+ base_line_size = base_size / 22,
+ base_rect_size = base_size / 22) {
half_line <- base_size / 2
theme(
# Elements in this first block aren't used directly, but are inherited
# by others
- line = element_line(colour = "black", size = 0.5, linetype = 1,
- lineend = "butt"),
- rect = element_rect(fill = "white", colour = "black",
- size = 0.5, linetype = 1),
+ line = element_line(
+ colour = "black", size = base_line_size,
+ linetype = 1, lineend = "butt"
+ ),
+ rect = element_rect(
+ fill = "white", colour = "black",
+ size = base_rect_size, linetype = 1
+ ),
text = element_text(
family = base_family, face = "plain",
colour = "black", size = base_size,
@@ -177,9 +185,16 @@ theme_gray <- theme_grey
#' @export
#' @rdname ggtheme
-theme_bw <- function(base_size = 11, base_family = "") {
+theme_bw <- function(base_size = 11, base_family = "",
+ base_line_size = base_size / 22,
+ base_rect_size = base_size / 22) {
# Starts with theme_grey and then modify some parts
- theme_grey(base_size = base_size, base_family = base_family) %+replace%
+ theme_grey(
+ base_size = base_size,
+ base_family = base_family,
+ base_line_size = base_line_size,
+ base_rect_size = base_rect_size
+ ) %+replace%
theme(
# white background and dark border
panel.background = element_rect(fill = "white", colour = NA),
@@ -198,10 +213,17 @@ theme_bw <- function(base_size = 11, base_family = "") {
#' @export
#' @rdname ggtheme
-theme_linedraw <- function(base_size = 11, base_family = "") {
+theme_linedraw <- function(base_size = 11, base_family = "",
+ base_line_size = base_size / 22,
+ base_rect_size = base_size / 22) {
# Starts with theme_bw and then modify some parts
# = replace all greys with pure black or white
- theme_bw(base_size = base_size, base_family = base_family) %+replace%
+ theme_bw(
+ base_size = base_size,
+ base_family = base_family,
+ base_line_size = base_line_size,
+ base_rect_size = base_rect_size
+ ) %+replace%
theme(
# black text and ticks on the axes
axis.text = element_text(colour = "black", size = rel(0.8)),
@@ -224,9 +246,16 @@ theme_linedraw <- function(base_size = 11, base_family = "") {
#' @export
#' @rdname ggtheme
-theme_light <- function(base_size = 11, base_family = "") {
+theme_light <- function(base_size = 11, base_family = "",
+ base_line_size = base_size / 22,
+ base_rect_size = base_size / 22) {
# Starts with theme_grey and then modify some parts
- theme_grey(base_size = base_size, base_family = base_family) %+replace%
+ theme_grey(
+ base_size = base_size,
+ base_family = base_family,
+ base_line_size = base_line_size,
+ base_rect_size = base_rect_size
+ ) %+replace%
theme(
# white panel with light grey border
panel.background = element_rect(fill = "white", colour = NA),
@@ -253,9 +282,16 @@ theme_light <- function(base_size = 11, base_family = "") {
#' @export
#' @rdname ggtheme
-theme_dark <- function(base_size = 11, base_family = "") {
+theme_dark <- function(base_size = 11, base_family = "",
+ base_line_size = base_size / 22,
+ base_rect_size = base_size / 22) {
# Starts with theme_grey and then modify some parts
- theme_grey(base_size = base_size, base_family = base_family) %+replace%
+ theme_grey(
+ base_size = base_size,
+ base_family = base_family,
+ base_line_size = base_line_size,
+ base_rect_size = base_rect_size
+ ) %+replace%
theme(
# dark panel
panel.background = element_rect(fill = "grey50", colour = NA),
@@ -280,9 +316,16 @@ theme_dark <- function(base_size = 11, base_family = "") {
#' @export
#' @rdname ggtheme
-theme_minimal <- function(base_size = 11, base_family = "") {
+theme_minimal <- function(base_size = 11, base_family = "",
+ base_line_size = base_size / 22,
+ base_rect_size = base_size / 22) {
# Starts with theme_bw and remove most parts
- theme_bw(base_size = base_size, base_family = base_family) %+replace%
+ theme_bw(
+ base_size = base_size,
+ base_family = base_family,
+ base_line_size = base_line_size,
+ base_rect_size = base_rect_size
+ ) %+replace%
theme(
axis.ticks = element_blank(),
legend.background = element_blank(),
@@ -298,8 +341,15 @@ theme_minimal <- function(base_size = 11, base_family = "") {
#' @export
#' @rdname ggtheme
-theme_classic <- function(base_size = 11, base_family = ""){
- theme_bw(base_size = base_size, base_family = base_family) %+replace%
+theme_classic <- function(base_size = 11, base_family = "",
+ base_line_size = base_size / 22,
+ base_rect_size = base_size / 22) {
+ theme_bw(
+ base_size = base_size,
+ base_family = base_family,
+ base_line_size = base_line_size,
+ base_rect_size = base_rect_size
+ ) %+replace%
theme(
# no background and no grid
panel.border = element_blank(),
@@ -322,7 +372,9 @@ theme_classic <- function(base_size = 11, base_family = ""){
#' @export
#' @rdname ggtheme
-theme_void <- function(base_size = 11, base_family = "") {
+theme_void <- function(base_size = 11, base_family = "",
+ base_line_size = base_size / 22,
+ base_rect_size = base_size / 22) {
theme(
# Use only inherited elements and make almost everything blank
# Only keep indispensable text
@@ -347,14 +399,20 @@ theme_void <- function(base_size = 11, base_family = "") {
#' @export
#' @rdname ggtheme
-theme_test <- function(base_size = 11, base_family = "") {
+theme_test <- function(base_size = 11, base_family = "",
+ base_line_size = base_size / 22,
+ base_rect_size = base_size / 22) {
half_line <- base_size / 2
-
+
theme(
- line = element_line(colour = "black", size = 0.5, linetype = 1,
- lineend = "butt"),
- rect = element_rect(fill = "white", colour = "black",
- size = 0.5, linetype = 1),
+ line = element_line(
+ colour = "black", size = base_line_size,
+ linetype = 1, lineend = "butt"
+ ),
+ rect = element_rect(
+ fill = "white", colour = "black",
+ size = base_rect_size, linetype = 1
+ ),
text = element_text(
family = base_family, face = "plain",
colour = "black", size = base_size,
diff --git a/man/ggtheme.Rd b/man/ggtheme.Rd
index 4690576527..4501d6cd38 100644
--- a/man/ggtheme.Rd
+++ b/man/ggtheme.Rd
@@ -13,30 +13,38 @@
\alias{theme_test}
\title{Complete themes}
\usage{
-theme_grey(base_size = 11, base_family = "")
+theme_grey(base_size = 11, base_family = "", base_line_size, base_rect_size)
-theme_gray(base_size = 11, base_family = "")
+theme_gray(base_size = 11, base_family = "", base_line_size, base_rect_size)
-theme_bw(base_size = 11, base_family = "")
+theme_bw(base_size = 11, base_family = "", base_line_size, base_rect_size)
-theme_linedraw(base_size = 11, base_family = "")
+theme_linedraw(base_size = 11, base_family = "", base_line_size,
+ base_rect_size)
-theme_light(base_size = 11, base_family = "")
+theme_light(base_size = 11, base_family = "", base_line_size,
+ base_rect_size)
-theme_dark(base_size = 11, base_family = "")
+theme_dark(base_size = 11, base_family = "", base_line_size, base_rect_size)
-theme_minimal(base_size = 11, base_family = "")
+theme_minimal(base_size = 11, base_family = "", base_line_size,
+ base_rect_size)
-theme_classic(base_size = 11, base_family = "")
+theme_classic(base_size = 11, base_family = "", base_line_size,
+ base_rect_size)
-theme_void(base_size = 11, base_family = "")
+theme_void(base_size = 11, base_family = "", base_line_size, base_rect_size)
-theme_test(base_size = 11, base_family = "")
+theme_test(base_size = 11, base_family = "", base_line_size, base_rect_size)
}
\arguments{
\item{base_size}{base font size}
\item{base_family}{base font family}
+
+\item{base_line_size}{base size for line elements}
+
+\item{base_rect_size}{base size for rect elements}
}
\description{
These are complete themes which control all non-data display. Use
diff --git a/tests/figs/themes/theme-bw-large.svg b/tests/figs/themes/theme-bw-large.svg
new file mode 100644
index 0000000000..168b3176c0
--- /dev/null
+++ b/tests/figs/themes/theme-bw-large.svg
@@ -0,0 +1,92 @@
+
+
diff --git a/tests/figs/themes/theme-classic-large.svg b/tests/figs/themes/theme-classic-large.svg
new file mode 100644
index 0000000000..05160ef4e2
--- /dev/null
+++ b/tests/figs/themes/theme-classic-large.svg
@@ -0,0 +1,73 @@
+
+
diff --git a/tests/figs/themes/theme-dark-large.svg b/tests/figs/themes/theme-dark-large.svg
new file mode 100644
index 0000000000..508d062d11
--- /dev/null
+++ b/tests/figs/themes/theme-dark-large.svg
@@ -0,0 +1,91 @@
+
+
diff --git a/tests/figs/themes/theme-gray-large.svg b/tests/figs/themes/theme-gray-large.svg
new file mode 100644
index 0000000000..8cbe59ad5d
--- /dev/null
+++ b/tests/figs/themes/theme-gray-large.svg
@@ -0,0 +1,91 @@
+
+
diff --git a/tests/figs/themes/theme-light-large.svg b/tests/figs/themes/theme-light-large.svg
new file mode 100644
index 0000000000..376744cdc4
--- /dev/null
+++ b/tests/figs/themes/theme-light-large.svg
@@ -0,0 +1,92 @@
+
+
diff --git a/tests/figs/themes/theme-linedraw-large.svg b/tests/figs/themes/theme-linedraw-large.svg
new file mode 100644
index 0000000000..1080da4da6
--- /dev/null
+++ b/tests/figs/themes/theme-linedraw-large.svg
@@ -0,0 +1,92 @@
+
+
diff --git a/tests/figs/themes/theme-minimal-large.svg b/tests/figs/themes/theme-minimal-large.svg
new file mode 100644
index 0000000000..406f8312aa
--- /dev/null
+++ b/tests/figs/themes/theme-minimal-large.svg
@@ -0,0 +1,75 @@
+
+
diff --git a/tests/figs/themes/theme-void-large.svg b/tests/figs/themes/theme-void-large.svg
new file mode 100644
index 0000000000..9cc52d5676
--- /dev/null
+++ b/tests/figs/themes/theme-void-large.svg
@@ -0,0 +1,45 @@
+
+
diff --git a/tests/testthat/test-theme.r b/tests/testthat/test-theme.r
index 7b3da1d4f6..0483ef38ea 100644
--- a/tests/testthat/test-theme.r
+++ b/tests/testthat/test-theme.r
@@ -253,3 +253,18 @@ test_that("themes don't change without acknowledgement", {
vdiffr::expect_doppelganger("theme_linedraw", plot + theme_linedraw())
})
+test_that("themes look decent at larger base sizes", {
+ df <- data.frame(x = 1:3, y = 1:3, z = c("a", "b", "a"), a = 1)
+ plot <- ggplot(df, aes(x, y, colour = z)) +
+ geom_point() +
+ facet_wrap(~ a)
+
+ vdiffr::expect_doppelganger("theme_bw_large", plot + theme_bw(base_size = 33))
+ vdiffr::expect_doppelganger("theme_classic_large", plot + theme_classic(base_size = 33))
+ vdiffr::expect_doppelganger("theme_dark_large", plot + theme_dark(base_size = 33))
+ vdiffr::expect_doppelganger("theme_minimal_large", plot + theme_minimal(base_size = 33))
+ vdiffr::expect_doppelganger("theme_gray_large", plot + theme_gray(base_size = 33))
+ vdiffr::expect_doppelganger("theme_light_large", plot + theme_light(base_size = 33))
+ vdiffr::expect_doppelganger("theme_void_large", plot + theme_void(base_size = 33))
+ vdiffr::expect_doppelganger("theme_linedraw_large", plot + theme_linedraw(base_size = 33))
+})