Skip to content

Commit d3e60ca

Browse files
committed
follow ggplot2 default theme setting
1 parent 798d0c3 commit d3e60ca

File tree

115 files changed

+213
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+213
-67
lines changed

NAMESPACE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ importFrom(ggplot2,element_grob)
534534
importFrom(ggplot2,element_line)
535535
importFrom(ggplot2,element_rect)
536536
importFrom(ggplot2,element_render)
537-
importFrom(ggplot2,element_text)
538537
importFrom(ggplot2,find_panel)
539538
importFrom(ggplot2,ggplot)
540539
importFrom(ggplot2,ggplotGrob)
@@ -548,7 +547,7 @@ importFrom(ggplot2,register_theme_elements)
548547
importFrom(ggplot2,rel)
549548
importFrom(ggplot2,resolution)
550549
importFrom(ggplot2,theme)
551-
importFrom(ggplot2,theme_classic)
550+
importFrom(ggplot2,theme_bw)
552551
importFrom(ggplot2,theme_get)
553552
importFrom(ggplot2,update_labels)
554553
importFrom(ggplot2,waiver)

R/align-dendrogram.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ align_dendro <- function(mapping = aes(), ...,
124124
),
125125
no_axes = no_axes, active = active,
126126
size = size,
127-
schemes = default_schemes(th = theme_no_panel()),
127+
schemes = default_schemes(th = theme_no_strip()),
128128
data = data,
129129
plot = plot
130130
)

R/cross-link.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ cross_link <- function(link, data = waiver(), on_top = TRUE,
2828
cross(CrossLink,
2929
data = data, link = link, reorder = reorder, obs_size = obs_size,
3030
plot = ggplot(), size = size,
31-
schemes = default_schemes(th = theme_no_panel()),
31+
schemes = default_schemes(),
3232
active = active,
3333
on_top = on_top,
3434
inherit_nobs = inherit_nobs,

R/cross-mark.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ cross_mark <- function(mark, data = waiver(), reorder = NULL, obs_size = 1,
3737
cross(CrossMark,
3838
data = data, mark = mark, reorder = reorder, obs_size = obs_size,
3939
plot = ggplot(), size = size,
40-
schemes = default_schemes(th = theme_add_panel()),
40+
schemes = default_schemes(),
4141
active = active,
4242
inherit_nobs = inherit_nobs,
4343
inherit_panel = inherit_panel,

R/ggalign.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ ggalign <- function(data = waiver(), mapping = aes(), ..., size = NULL,
102102
params = list2(...),
103103
plot = ggplot(mapping = mapping),
104104
size = size,
105-
schemes = default_schemes(data, th = theme_no_panel()),
105+
schemes = default_schemes(data, th = theme_no_strip()),
106106
no_axes = no_axes, active = active
107107
)
108108
}

R/ggcross.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ggcross <- function(mapping = aes(), size = NULL,
4646
cross(
4747
cross = CrossGg,
4848
plot = ggplot(mapping = mapping),
49-
schemes = default_schemes(th = theme_no_panel()),
49+
schemes = default_schemes(th = theme_no_strip()),
5050
size = size, no_axes = no_axes, active = active
5151
)
5252
}

R/ggmark.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ ggmark <- function(mark, data = waiver(), mapping = aes(), ...,
8181
# slot
8282
plot = ggplot(mapping = mapping),
8383
size = size,
84-
schemes = default_schemes(data, th = theme_add_panel()),
84+
schemes = default_schemes(data),
8585
active = active
8686
)
8787
}

R/ggplot-theme.R

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,30 @@
1-
#' @importFrom ggplot2 theme_classic
2-
default_theme <- function() theme_classic()
1+
#' @importFrom ggplot2 theme_bw element_blank
2+
default_theme <- function() {
3+
if (is_theme_unset()) {
4+
theme_bw() + theme(
5+
panel.border = element_blank(),
6+
panel.grid = element_blank()
7+
)
8+
} else {
9+
theme_get()
10+
}
11+
}
312

4-
#' @importFrom ggplot2 rel element_line element_rect element_text
5-
theme_add_panel <- function(base_size = 11) {
6-
half_line <- base_size / 2
7-
theme(
8-
panel.border = element_rect(fill = NA, colour = "grey20"),
9-
panel.grid = element_line(colour = "grey92"),
10-
panel.grid.minor = element_line(linewidth = rel(0.5)),
11-
panel.background = element_rect(fill = "white", colour = NA),
12-
strip.background = element_rect(
13-
fill = "white", colour = "black", linewidth = rel(2)
14-
),
15-
strip.clip = "inherit",
16-
strip.text = element_text(
17-
colour = "grey10", size = rel(0.8),
18-
margin = margin(
19-
0.8 * half_line, 0.8 * half_line,
20-
0.8 * half_line, 0.8 * half_line
21-
)
22-
),
23-
strip.text.x = NULL,
24-
strip.text.y = element_text(angle = -90),
25-
strip.text.y.left = element_text(angle = 90)
26-
)
13+
# Check if user has set the theme
14+
is_theme_unset <- function() {
15+
isTRUE(all.equal(
16+
.subset2(ggfun("ggplot_global"), "theme_default"),
17+
complete_theme(theme_get())
18+
))
2719
}
2820

29-
#' @importFrom ggplot2 element_blank
30-
theme_no_panel <- function(...) {
21+
is_theme_complete <- function(x) isTRUE(attr(x, "complete", exact = TRUE))
22+
23+
#' @importFrom ggplot2 rel element_blank
24+
theme_no_strip <- function() {
3125
theme(
32-
panel.border = element_blank(),
33-
panel.grid.major = element_blank(),
34-
panel.grid.minor = element_blank(),
35-
axis.line = element_blank(),
3626
strip.text = element_blank(),
37-
strip.background = element_blank(),
38-
plot.background = element_blank()
27+
strip.background = element_blank()
3928
)
4029
}
4130

@@ -47,8 +36,6 @@ complete_theme <- function(theme) {
4736
)
4837
}
4938

50-
is_theme_complete <- function(x) isTRUE(attr(x, "complete", exact = TRUE))
51-
5239
#' @importFrom ggplot2 register_theme_elements el_def element_line
5340
theme_elements <- function() {
5441
register_theme_elements(

R/ggplot-utils.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ ggadd_default <- function(plot, mapping = NULL, theme = NULL) {
3939
plot
4040
}
4141

42+
is_palette_unset <- function(type, aes) {
43+
type <- match.arg(type, c("discrete", "continuous", "binned"))
44+
aes <- match.arg(aes, c("fill", "colour"))
45+
is.null(getOption(sprintf("ggplot2.%s.%s", type, aes)))
46+
}
47+
4248
######################################################
4349
gguse_data <- function(plot, data) {
4450
# ggplot use waiver() to indicate no data

R/layout-quad-.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ new_quad_layout <- function(name, data, xlim = waiver(), ylim = waiver(),
237237
if (!is.waive(xlim)) assert_limits(xlim, call = call)
238238
if (!is.waive(ylim)) assert_limits(ylim, call = call)
239239
if (is.waive(xlim) || is.waive(ylim)) {
240-
# If we need align discrete variables, data cannot be `NULL` and
241-
# must be provided, here, we convert it to waiver() to indicate
240+
# If we need align discrete variables, data cannot be `NULL` and
241+
# must be provided, here, we convert it to waiver() to indicate
242242
# inherit from the parent layout
243243
data <- data %||% waiver()
244244
if (!is.waive(data) && !is.function(data)) {
@@ -270,7 +270,7 @@ new_quad_layout <- function(name, data, xlim = waiver(), ylim = waiver(),
270270
# the action data function
271271
schemes <- default_schemes(
272272
if (is.null(data)) waiver() else NULL,
273-
th = theme_no_panel()
273+
th = theme_no_strip()
274274
)
275275

276276
# check arguments -----------------------------------

0 commit comments

Comments
 (0)