Skip to content

Commit a2d2e77

Browse files
Improved dark theme
1 parent aabe94b commit a2d2e77

File tree

2 files changed

+93
-62
lines changed

2 files changed

+93
-62
lines changed

app.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ plot_data <- reactive({
15491549

15501550
# This needs to go here (before annotations)
15511551
p <- p+ theme_light(base_size = 16)
1552-
if (input$dark) {p <- p+ theme_dark_basic(base_size = 16)}
1552+
if (input$dark) {p <- p+ theme_light_dark_bg(base_size = 16)}
15531553

15541554

15551555
############## Adjust Y-scaling if necessary ##########

themes.R

Lines changed: 92 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -60,65 +60,52 @@ theme_darker <- function(base_size = 11, base_family = "", base_line_size = bas
6060

6161
}
6262

63-
theme_dark_basic <- function(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22)
64-
{
65-
half_line <- base_size/2
66-
theme_light() %+replace%
67-
theme(line = element_line(colour = "grey100", size = 0.5, linetype = 1, lineend = "butt"),
68-
69-
rect = element_rect(fill = "grey0", colour = "grey100", size = 0.5, linetype = 1),
70-
71-
text = element_text(family = base_family, face = "plain", colour = "grey100", size = base_size, lineheight = 0.9, hjust = 0.5, vjust = 0.5, angle = 0, margin = margin(), debug = FALSE),
72-
73-
axis.line = element_line(),
74-
axis.line.x = element_blank(),
75-
axis.line.y = element_blank(),
76-
77-
axis.text = element_text(size = rel(0.8), colour = "grey80"),
78-
# axis.text.x = element_text(margin = margin(t = 0.8 * half_line/2), vjust = 1),
79-
# axis.text.y = element_text(margin = margin(r = 0.8 * half_line/2), hjust = 1),
80-
81-
axis.ticks = element_line(colour = "grey80"),
82-
# axis.ticks.length = unit(half_line/2, "pt"),
83-
84-
# axis.title.x = element_text(margin = margin(t = 0.8 * half_line, b = 0.8 * half_line/2)),
85-
# axis.title.y = element_text(angle = 90, margin = margin(r = 0.8 * half_line, l = 0.8 * half_line/2)),
86-
87-
legend.background = element_rect(colour = NA),
88-
# legend.margin = unit(0.2, "cm"),
89-
legend.key = element_rect(fill = NULL, colour = "grey0"),
90-
# legend.key.size = unit(1.2, "lines"),
91-
# legend.key.height = NULL, legend.key.width = NULL,
92-
# legend.text = element_text(size = rel(0.8)),
93-
# legend.text.align = NULL,
94-
# legend.title = element_text(hjust = 0),
95-
# legend.title.align = NULL,
96-
# legend.position = "right",
97-
# legend.direction = NULL,
98-
# legend.justification = "center",
99-
# legend.box = NULL,
100-
101-
panel.background = element_rect(fill = "grey5", colour = NA),
102-
panel.border = element_rect(fill = NA, colour = "grey80"),
103-
panel.grid.major = element_line(colour = "grey30"),
104-
panel.grid.minor = element_line(colour = "grey30", size = 0.25),
105-
# panel.margin = unit(half_line, "pt"),
106-
# panel.margin.x = NULL,
107-
# panel.margin.y = NULL,
108-
panel.ontop = FALSE,
109-
110-
strip.background = element_rect(fill = "grey40", colour = NA),
111-
strip.text = element_text(colour = "grey10", size = rel(0.8)),
112-
strip.text.x = element_text(margin = margin(t = half_line, b = half_line)),
113-
strip.text.y = element_text(angle = -90, margin = margin(l = half_line, r = half_line)),
114-
strip.switch.pad.grid = unit(0.1, "cm"),
115-
strip.switch.pad.wrap = unit(0.1, "cm"),
116-
117-
#To avoid white line around plot panel
118-
plot.background = element_rect(colour = "black"),
119-
# plot.title = element_text(size = rel(1.2), margin = margin(b = half_line * 1.2)),
120-
# plot.margin = margin(half_line, half_line, half_line, half_line),
121-
complete = TRUE)
63+
theme_light_dark_bg <- function(base_size = 11, base_family = "",
64+
base_line_size = base_size / 22,
65+
base_rect_size = base_size / 22) {
66+
half_line <- base_size / 2
67+
68+
# Starts with theme_grey and then modify some parts
69+
theme_grey(
70+
base_size = base_size,
71+
base_family = base_family,
72+
base_line_size = base_line_size,
73+
base_rect_size = base_rect_size
74+
) %+replace%
75+
theme(
76+
plot.background = element_rect(colour = "black", fill="black"),
77+
text = element_text(family = base_family, face = "plain", colour = "grey100", size = base_size,
78+
lineheight = 0.9, hjust = 0.5, vjust = 0.5, angle = 0, margin = margin(), debug = FALSE) ,
79+
axis.text = element_text(size = rel(0.8),colour = "grey80"),
80+
81+
82+
# axis.text = element_text(colour = "grey80"),
83+
84+
# white panel with light grey border
85+
panel.background = element_rect(fill = "grey5", colour = NA),
86+
panel.border = element_rect(fill = NA, colour = "grey80", size = rel(1)),
87+
# light grey, thinner gridlines
88+
# => make them slightly darker to keep acceptable contrast
89+
panel.grid = element_line(colour = "grey30"),
90+
panel.grid.major = element_line(size = rel(0.5)),
91+
panel.grid.minor = element_line(size = rel(0.25)),
92+
93+
# match axes ticks thickness to gridlines and colour to panel border
94+
axis.ticks = element_line(colour = "grey80", size = rel(0.5)),
95+
96+
# match legend key to panel.background
97+
legend.key = element_rect(fill = NA, colour = NA),
98+
99+
# dark strips with light text (inverse contrast compared to theme_grey)
100+
strip.background = element_rect(fill = "grey40", colour = NA),
101+
strip.text = element_text(
102+
colour = "grey10",
103+
size = rel(0.8),
104+
margin = margin(0.8 * half_line, 0.8 * half_line, 0.8 * half_line, 0.8 * half_line)
105+
),
106+
107+
complete = TRUE
108+
)
122109

123110
}
124111

@@ -175,7 +162,7 @@ blue_theme <- function() {
175162

176163

177164

178-
####### Definition of the 'official' grey ggplot2 theme
165+
####### Definition of the 'official' ggplot2 theme_grey
179166

180167

181168
# theme_grey <- function (base_size = 11, base_family = "")
@@ -214,4 +201,48 @@ blue_theme <- function() {
214201
# plot.title = element_text(size = rel(1.2), margin = margin(b = half_line *
215202
# 1.2)), plot.margin = margin(half_line, half_line,
216203
# half_line, half_line), complete = TRUE)
217-
# }
204+
# }
205+
206+
207+
####### Definition of the ggplot2 theme_light
208+
#
209+
# theme_light <- function(base_size = 11, base_family = "",
210+
# base_line_size = base_size / 22,
211+
# base_rect_size = base_size / 22) {
212+
# half_line <- base_size / 2
213+
#
214+
# # Starts with theme_grey and then modify some parts
215+
# theme_grey(
216+
# base_size = base_size,
217+
# base_family = base_family,
218+
# base_line_size = base_line_size,
219+
# base_rect_size = base_rect_size
220+
# ) %+replace%
221+
# theme(
222+
# # white panel with light grey border
223+
# panel.background = element_rect(fill = "white", colour = NA),
224+
# panel.border = element_rect(fill = NA, colour = "grey70", size = rel(1)),
225+
# # light grey, thinner gridlines
226+
# # => make them slightly darker to keep acceptable contrast
227+
# panel.grid = element_line(colour = "grey87"),
228+
# panel.grid.major = element_line(size = rel(0.5)),
229+
# panel.grid.minor = element_line(size = rel(0.25)),
230+
#
231+
# # match axes ticks thickness to gridlines and colour to panel border
232+
# axis.ticks = element_line(colour = "grey70", size = rel(0.5)),
233+
#
234+
# # match legend key to panel.background
235+
# legend.key = element_rect(fill = "white", colour = NA),
236+
#
237+
# # dark strips with light text (inverse contrast compared to theme_grey)
238+
# strip.background = element_rect(fill = "grey70", colour = NA),
239+
# strip.text = element_text(
240+
# colour = "white",
241+
# size = rel(0.8),
242+
# margin = margin(0.8 * half_line, 0.8 * half_line, 0.8 * half_line, 0.8 * half_line)
243+
# ),
244+
#
245+
# complete = TRUE
246+
# )
247+
#
248+
# }

0 commit comments

Comments
 (0)