-
Notifications
You must be signed in to change notification settings - Fork 1
/
theme_ggswim.R
78 lines (72 loc) · 2.27 KB
/
theme_ggswim.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#' @title
#' Apply custom theme styling for ggplot2 plots
#'
#' @description
#' This function applies custom styling to various elements of ggplot2 plots,
#' including title, subtitle, caption, axis text, axis titles, and legend text
#' and legend titles.
#'
#' @details
#' This function builds upon the `theme_minimal()` function in ggplot2 but overrides
#' specific theme elements to provide a customized look and feel for plots.
#'
#' @param base_size The base font size to use for the plot elements. Default is 12.
#' @param base_family The base font family to use for the plot elements. Default is "".
#'
#' @return A ggplot2 theme object.
#'
#' @export
#'
#' @examples
#' p <- ggplot2::ggplot(data = patient_data) +
#' geom_swim_lane(
#' mapping = aes(
#' x = start_time,
#' y = pt_id,
#' xend = end_time,
#' color = disease_assessment
#' )
#' ) +
#' ggplot2::scale_color_brewer(name = "Lanes", palette = "Set1") +
#' new_scale_color() +
#' geom_swim_point(
#' data = infusion_events,
#' mapping = aes(
#' x = time_from_initial_infusion,
#' y = pt_id, color = infusion_type
#' ), # nolint: object_usage_linter
#' size = 5
#' ) +
#' ggplot2::scale_color_manual(name = "Markers", values = c("red", "green"))
#'
#' p +
#' theme_ggswim()
theme_ggswim <- function(base_size = 12, base_family = "") {
theme_minimal(base_size = base_size, base_family = base_family) +
theme(
# Title and subtitle
plot.title = element_text(size = 18, face = "bold", hjust = 0, margin = margin(b = 10)),
plot.subtitle = element_text(size = 14, hjust = 0, margin = margin(b = 10)),
# Caption
plot.caption = element_text(size = 10, hjust = 1),
# Axis text
axis.text = element_text(size = 10),
# Axis titles
axis.title = element_text(size = 12, face = "bold"),
# Legend
legend.text = element_text(size = 10),
legend.title = element_text(size = 12, face = "bold"),
# Axis line
axis.line = element_line(
color = "steelblue",
linewidth = .5,
arrow = arrow(
type = "closed",
length = unit(0.2, "inches")
)
),
# Remove grid lines
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
)
}