Skip to content

Commit 21b58aa

Browse files
committed
fix(theme): correct styling issue in theme_cat
1 parent 45bacc8 commit 21b58aa

2 files changed

Lines changed: 46 additions & 14 deletions

File tree

R/theme_cat.R

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
#' @param aspect_ratio Numeric, aspect ratio of the plot (default: NULL)
77
#' @param frame Character, frame type, "none","closed" or "open" (default:
88
#' "closed")
9-
#' @param show_panel_grid Character, panel grid visibility (default: "none")
9+
#' @param show_panel_grid_marjor Character, major panel grid visibility
10+
#' (default: "none")
11+
#' @param show_panel_grid_minor Character, minor panel grid visibility
12+
#' (default: "none")
13+
#' @param panel_widths Numeric vector, panel widths in pt (default: NULL)
14+
#' @param panel_heights Numeric vector, panel heights in pt (default: NULL)
1015
#' @param show_title Character, axis title visibility (default: "both")
1116
#' @param show_text Character, axis text visibility (default: "both")
1217
#' @param text_italic Character, axis text italicization (default: "none")
@@ -33,7 +38,8 @@ theme_cat <- function(
3338
panel_heights = NULL,
3439
aspect_ratio = NULL,
3540
frame = "open",
36-
show_panel_grid = "none",
41+
show_panel_grid_marjor = "none",
42+
show_panel_grid_minor = "none",
3743
show_title = "both",
3844
show_text = "both",
3945
text_italic = "none",
@@ -52,9 +58,14 @@ theme_cat <- function(
5258
panel_heights <- if (!is.null(panel_heights)) {
5359
unit(panel_heights, "pt")
5460
}
61+
# panel_widths and panel_heights can not be set together with aspect_ratio
62+
if (!is.null(aspect_ratio) && (!is.null(panel_widths) || !is.null(panel_heights))) {
63+
abort("`aspect_ratio` cannot be set together with `panel_widths` or `panel_heights`.")
64+
}
5565

5666
arg_match0(arg = frame, values = c("none", "closed", "open"))
57-
arg_match0(arg = show_panel_grid, values = c("none", "x", "y", "both"))
67+
arg_match0(arg = show_panel_grid_marjor, values = c("none", "x", "y", "both"))
68+
arg_match0(arg = show_panel_grid_minor, values = c("none", "x", "y", "both"))
5869
arg_match0(arg = show_title, values = c("none", "x", "y", "both"))
5970
arg_match0(arg = show_text, values = c("none", "x", "y", "both"))
6071
arg_match0(arg = text_italic, values = c("none", "x", "y", "both"))
@@ -81,7 +92,8 @@ theme_cat <- function(
8192
family = font_family,
8293
size = base_font_size,
8394
face = "plain",
84-
colour = "black"
95+
colour = "black",
96+
margin = margin()
8597
)
8698
} else {
8799
legend_title <- element_blank()
@@ -176,15 +188,27 @@ theme_cat <- function(
176188
axis_ticks_y <- element_blank()
177189
}
178190
# Panel grid
179-
if (show_panel_grid %in% c("x", "both")) {
180-
panel_grid_x <- grid_element
191+
## panel_grid_major
192+
if (show_panel_grid_marjor %in% c("x", "both")) {
193+
panel_grid_major_x <- grid_element
194+
} else {
195+
panel_grid_major_x <- element_blank()
196+
}
197+
if (show_panel_grid_marjor %in% c("y", "both")) {
198+
panel_grid_major_y <- grid_element
199+
} else {
200+
panel_grid_major_y <- element_blank()
201+
}
202+
## panel_grid_minor
203+
if (show_panel_grid_minor %in% c("x", "both")) {
204+
panel_grid_minor_x <- grid_element
181205
} else {
182-
panel_grid_x <- element_blank()
206+
panel_grid_minor_x <- element_blank()
183207
}
184-
if (show_panel_grid %in% c("y", "both")) {
185-
panel_grid_y <- grid_element
208+
if (show_panel_grid_minor %in% c("y", "both")) {
209+
panel_grid_minor_y <- grid_element
186210
} else {
187-
panel_grid_y <- element_blank()
211+
panel_grid_minor_y <- element_blank()
188212
}
189213
# Panel border & axis line
190214
if (frame == "closed") {

man/theme_cat.Rd

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)