-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathggtheme_publication.R
103 lines (96 loc) · 4.85 KB
/
ggtheme_publication.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
###############################################################
## Publication-ready themes for ggplot2
## Legend control refers to www.tidyverse.org/blog/2024/02/ggplot2-3-5-0-legends/
###############################################################
library(ggplot2)
# Define variables for standard linewidths: 0.18 mm, 0.25 mm, 0.35 mm, 0.5 mm, 0.70 mm, 1 mm
lw18 <- 0.18/0.75
lw25 <- 0.25/0.75
lw35 <- 0.35/0.75
lw50 <- 0.50/0.75
lw70 <- 0.70/0.75
lw100 <- 1.00/0.75
# Set default line width to 0.18mm for the geom objects and text size to 9 pt
update_geom_defaults("line", list(linewidth = lw18))
update_geom_defaults("path", list(linewidth = lw18))
update_geom_defaults("point", list(stroke = lw18, size = lw50))
update_geom_defaults("bar", list(linewidth = lw18))
update_geom_defaults("pointrange", list(linewidth = lw18, stroke = lw18, size = lw18))
update_geom_defaults("linerange", list(linewidth = lw18))
update_geom_defaults("sf", list(linewidth = lw18))
update_geom_defaults("segment", list(linewidth = lw18))
update_geom_defaults("abline", list(linewidth = lw18))
update_geom_defaults("hline", list(linewidth = lw18))
update_geom_defaults("vline", list(linewidth = lw18))
update_geom_defaults("text", list(size = 9/.pt))
# theme with a box border for the plot region
theme_boxborder <- function(base_size = 9,
base_family = "",
base_line_size = lw18,
base_rect_size = lw18) {
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.text = element_text(size = rel(0.9), colour = "black"),
axis.ticks = element_line(colour = "black", linewidth = rel(1)),
legend.position = c(0.99, 0.99),
legend.justification = c("right", "top"),
legend.background = element_blank(),
legend.key = element_blank(),
legend.key.width = unit(1.2, "lines"),
legend.key.height = unit(0.8, "lines"),
# legend.text = element_text(size = rel(0.9)), # legend text size
legend.title = element_text(size = rel(0.9)),
legend.margin = margin(0.1, 0.1, 0.1, 0.1, unit = "lines"),
legend.box.background = element_blank(),
panel.grid = element_blank(),
panel.border = element_rect(fill = NA, colour = "black", linewidth = rel(1)),
panel.background = element_blank(),
strip.background = element_rect(fill = NA, colour = NA),
strip.text = element_text(colour = "black", size = rel(1),
margin = margin(0.1, 0.1, 0.1, 0.1, unit = "lines")),
plot.background = element_blank(),
plot.title = element_text(size = rel(1.2), hjust = 0.5, margin = margin(b = base_size/4), face = "bold"),
plot.tag = element_text(size = rel(1.15), face = "bold"),
plot.tag.position = c(0.05, 0.98),
plot.margin = margin(t = base_size/3*2, r = base_size, b = base_size/4, l = base_size/4, unit = "pt"),
complete = TRUE
)
}
# theme with a L border for the plot region
theme_lborder <- function(base_size = 9,
base_family = "",
base_line_size = lw18,
base_rect_size = lw18) {
theme_classic(base_size = base_size,
base_family = base_family,
base_line_size = base_line_size,
base_rect_size = base_rect_size) %+replace%
theme(
axis.text = element_text(size = rel(0.9), colour = "black"),
axis.ticks = element_line(colour = "black", linewidth = rel(1)),
axis.line = element_line(colour = "black", linewidth = rel(1)),
legend.position = c(0.99, 0.99),
legend.justification = c("right", "top"),
legend.background = element_blank(),
legend.key = element_blank(),
legend.key.width = unit(1.2, "lines"),
legend.key.height = unit(0.8, "lines"),
#legend.text = element_text(size = rel(0.9)), # legend text size
legend.title = element_text(size = rel(0.9)),
legend.margin = margin(0.1, 0.1, 0.1, 0.1, unit = "lines"),
legend.box.background = element_blank(),
panel.background = element_blank(),
strip.background = element_rect(fill = NA, colour = NA),
strip.text = element_text(colour = "black", size = rel(1),
margin = margin(0.1, 0.1, 0.1, 0.1, unit = "lines")),
plot.background = element_blank(),
plot.title = element_text(size = rel(1.2), hjust = 0.5, margin = margin(b = base_size/4), face = "bold"),
plot.tag = element_text(size = rel(1.15), face = "bold"),
plot.tag.position = c(0.05, 0.98),
plot.margin = margin(t = base_size/3*2, r = base_size, b = base_size/4, l = base_size/4, unit = "pt"),
complete = TRUE
)
}