Skip to content

Commit

Permalink
follow ggplot2 default theme setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jan 6, 2025
1 parent 798d0c3 commit d3e60ca
Show file tree
Hide file tree
Showing 115 changed files with 213 additions and 67 deletions.
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ importFrom(ggplot2,element_grob)
importFrom(ggplot2,element_line)
importFrom(ggplot2,element_rect)
importFrom(ggplot2,element_render)
importFrom(ggplot2,element_text)
importFrom(ggplot2,find_panel)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggplotGrob)
Expand All @@ -548,7 +547,7 @@ importFrom(ggplot2,register_theme_elements)
importFrom(ggplot2,rel)
importFrom(ggplot2,resolution)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_classic)
importFrom(ggplot2,theme_bw)
importFrom(ggplot2,theme_get)
importFrom(ggplot2,update_labels)
importFrom(ggplot2,waiver)
Expand Down
2 changes: 1 addition & 1 deletion R/align-dendrogram.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ align_dendro <- function(mapping = aes(), ...,
),
no_axes = no_axes, active = active,
size = size,
schemes = default_schemes(th = theme_no_panel()),
schemes = default_schemes(th = theme_no_strip()),
data = data,
plot = plot
)
Expand Down
2 changes: 1 addition & 1 deletion R/cross-link.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cross_link <- function(link, data = waiver(), on_top = TRUE,
cross(CrossLink,
data = data, link = link, reorder = reorder, obs_size = obs_size,
plot = ggplot(), size = size,
schemes = default_schemes(th = theme_no_panel()),
schemes = default_schemes(),
active = active,
on_top = on_top,
inherit_nobs = inherit_nobs,
Expand Down
2 changes: 1 addition & 1 deletion R/cross-mark.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cross_mark <- function(mark, data = waiver(), reorder = NULL, obs_size = 1,
cross(CrossMark,
data = data, mark = mark, reorder = reorder, obs_size = obs_size,
plot = ggplot(), size = size,
schemes = default_schemes(th = theme_add_panel()),
schemes = default_schemes(),
active = active,
inherit_nobs = inherit_nobs,
inherit_panel = inherit_panel,
Expand Down
2 changes: 1 addition & 1 deletion R/ggalign.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ ggalign <- function(data = waiver(), mapping = aes(), ..., size = NULL,
params = list2(...),
plot = ggplot(mapping = mapping),
size = size,
schemes = default_schemes(data, th = theme_no_panel()),
schemes = default_schemes(data, th = theme_no_strip()),
no_axes = no_axes, active = active
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/ggcross.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ggcross <- function(mapping = aes(), size = NULL,
cross(
cross = CrossGg,
plot = ggplot(mapping = mapping),
schemes = default_schemes(th = theme_no_panel()),
schemes = default_schemes(th = theme_no_strip()),
size = size, no_axes = no_axes, active = active
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/ggmark.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ggmark <- function(mark, data = waiver(), mapping = aes(), ...,
# slot
plot = ggplot(mapping = mapping),
size = size,
schemes = default_schemes(data, th = theme_add_panel()),
schemes = default_schemes(data),
active = active
)
}
Expand Down
57 changes: 22 additions & 35 deletions R/ggplot-theme.R
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
#' @importFrom ggplot2 theme_classic
default_theme <- function() theme_classic()
#' @importFrom ggplot2 theme_bw element_blank
default_theme <- function() {
if (is_theme_unset()) {
theme_bw() + theme(
panel.border = element_blank(),
panel.grid = element_blank()
)
} else {
theme_get()
}
}

#' @importFrom ggplot2 rel element_line element_rect element_text
theme_add_panel <- function(base_size = 11) {
half_line <- base_size / 2
theme(
panel.border = element_rect(fill = NA, colour = "grey20"),
panel.grid = element_line(colour = "grey92"),
panel.grid.minor = element_line(linewidth = rel(0.5)),
panel.background = element_rect(fill = "white", colour = NA),
strip.background = element_rect(
fill = "white", colour = "black", linewidth = rel(2)
),
strip.clip = "inherit",
strip.text = element_text(
colour = "grey10", size = rel(0.8),
margin = margin(
0.8 * half_line, 0.8 * half_line,
0.8 * half_line, 0.8 * half_line
)
),
strip.text.x = NULL,
strip.text.y = element_text(angle = -90),
strip.text.y.left = element_text(angle = 90)
)
# Check if user has set the theme
is_theme_unset <- function() {
isTRUE(all.equal(
.subset2(ggfun("ggplot_global"), "theme_default"),
complete_theme(theme_get())
))
}

#' @importFrom ggplot2 element_blank
theme_no_panel <- function(...) {
is_theme_complete <- function(x) isTRUE(attr(x, "complete", exact = TRUE))

#' @importFrom ggplot2 rel element_blank
theme_no_strip <- function() {
theme(
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_blank(),
strip.text = element_blank(),
strip.background = element_blank(),
plot.background = element_blank()
strip.background = element_blank()
)
}

Expand All @@ -47,8 +36,6 @@ complete_theme <- function(theme) {
)
}

is_theme_complete <- function(x) isTRUE(attr(x, "complete", exact = TRUE))

#' @importFrom ggplot2 register_theme_elements el_def element_line
theme_elements <- function() {
register_theme_elements(
Expand Down
6 changes: 6 additions & 0 deletions R/ggplot-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ ggadd_default <- function(plot, mapping = NULL, theme = NULL) {
plot
}

is_palette_unset <- function(type, aes) {
type <- match.arg(type, c("discrete", "continuous", "binned"))
aes <- match.arg(aes, c("fill", "colour"))
is.null(getOption(sprintf("ggplot2.%s.%s", type, aes)))
}

######################################################
gguse_data <- function(plot, data) {
# ggplot use waiver() to indicate no data
Expand Down
6 changes: 3 additions & 3 deletions R/layout-quad-.R
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ new_quad_layout <- function(name, data, xlim = waiver(), ylim = waiver(),
if (!is.waive(xlim)) assert_limits(xlim, call = call)
if (!is.waive(ylim)) assert_limits(ylim, call = call)
if (is.waive(xlim) || is.waive(ylim)) {
# If we need align discrete variables, data cannot be `NULL` and
# must be provided, here, we convert it to waiver() to indicate
# If we need align discrete variables, data cannot be `NULL` and
# must be provided, here, we convert it to waiver() to indicate
# inherit from the parent layout
data <- data %||% waiver()
if (!is.waive(data) && !is.function(data)) {
Expand Down Expand Up @@ -270,7 +270,7 @@ new_quad_layout <- function(name, data, xlim = waiver(), ylim = waiver(),
# the action data function
schemes <- default_schemes(
if (is.null(data)) waiver() else NULL,
th = theme_no_panel()
th = theme_no_strip()
)

# check arguments -----------------------------------
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions tests/testthat/_snaps/layout-heatmap/continuous-labels.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions tests/testthat/_snaps/layout-heatmap/continuous-no-labels.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions tests/testthat/_snaps/layout-heatmap/discrete-labels.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d3e60ca

Please sign in to comment.