@@ -101,21 +101,21 @@ plot_source_overlap_heatmap <- function(data, cells = "source", facets = NULL, p
101
101
ggplot2 :: theme(
102
102
aspect.ratio = 1 , legend.position = " none" ,
103
103
strip.background = ggplot2 :: element_rect(
104
- color = " black" , fill = " darkgrey "
104
+ color = " black" , fill = " #3A3A3A "
105
105
)
106
- ) + ggplot2 :: scale_fill_gradient(low = " white" )
106
+ ) + ggplot2 :: scale_fill_gradient(low = " white" , high = " #23395B " )
107
107
# Removed legends here because they do not appear in correct order - maybe worth fixing in the future
108
108
facets <- unique(data $ facet )
109
109
110
110
for (i in seq_along(facets )) {
111
111
p <- p + ggnewscale :: new_scale_fill() + ggplot2 :: geom_tile(ggplot2 :: aes(fill = .data $ records ), data = data %> % dplyr :: filter(.data $ facet == facets [i ])) +
112
112
113
- ggplot2 :: scale_fill_gradient(low = " white" )
113
+ ggplot2 :: scale_fill_gradient(low = " white" , high = " #008080 " )
114
114
}
115
115
} else {
116
116
p <- p +
117
117
ggplot2 :: geom_tile() +
118
- ggplot2 :: scale_fill_gradient(low = " white" )
118
+ ggplot2 :: scale_fill_gradient(low = " white" , high = " #008080 " )
119
119
}
120
120
121
121
p +
@@ -153,7 +153,7 @@ plot_source_overlap_heatmap <- function(data, cells = "source", facets = NULL, p
153
153
dplyr :: mutate(dplyr :: across(dplyr :: starts_with(" DB" ), ~ stringr :: str_remove(.x , paste0(cells , " __" )))) %> %
154
154
ggplot2 :: ggplot(ggplot2 :: aes(.data $ DB1 , .data $ DB2 , fill = .data $ shares )) +
155
155
ggplot2 :: geom_tile(height = .9 ) +
156
- ggplot2 :: scale_fill_gradient(low = " white" , labels = scales :: percent , limits = c(0 , 1 )) +
156
+ ggplot2 :: scale_fill_gradient(low = " white" , high = " #008080 " , labels = scales :: percent , limits = c(0 , 1 )) +
157
157
ggplot2 :: geom_text(ggplot2 :: aes(label = fmt_pct(.data $ shares ), fill = NULL )) +
158
158
ggplot2 :: labs(
159
159
x = " " , y = " " , fill = " Overlap" ,
@@ -162,18 +162,12 @@ plot_source_overlap_heatmap <- function(data, cells = "source", facets = NULL, p
162
162
) +
163
163
ggplot2 :: scale_x_discrete(limits = rev(sources_order ), guide = ggplot2 :: guide_axis(angle = 45 )) +
164
164
ggplot2 :: scale_y_discrete(limits = sources_order ) +
165
- ggplot2 :: theme_light()
166
165
167
166
168
167
169
168
if (length(unique(data $ facet )) > 1 ) {
170
- p <- p + ggplot2 :: facet_wrap(ggplot2 :: vars(.data $ facet ), ncol = 1 ) +
171
- ggplot2 :: theme(
172
- aspect.ratio = 1 ,
173
- strip.background = ggplot2 :: element_rect(
174
- color = " black" , fill = " darkgrey"
175
- )
176
- )
169
+ p <- p + ggplot2 :: facet_wrap(ggplot2 :: vars(.data $ facet ), ncol = 1 )
170
+
177
171
}
178
172
p
179
173
}
@@ -219,11 +213,14 @@ plot_source_overlap_upset <- function(data, groups = "source", nsets = NULL, set
219
213
}
220
214
221
215
if (nsets > 5 ) message(" Plotting a large number of groups. Consider reducing nset or sub-setting the data." )
222
-
216
+
223
217
data %> %
224
218
data.frame () %> %
225
219
dplyr :: transmute(dplyr :: across(tidyselect :: vars_select_helpers $ where(is.logical ), as.numeric )) %> %
226
- UpSetR :: upset(nsets = nsets , order.by = order.by , sets.x.label = sets.x.label , mainbar.y.label = mainbar.y.label , ... )
220
+ UpSetR :: upset(nsets = nsets , order.by = order.by ,
221
+ sets.x.label = sets.x.label ,
222
+ text.scale = 1.8 ,
223
+ mainbar.y.label = mainbar.y.label , ... )
227
224
}
228
225
229
226
# Hack to suppress check warning re default values below
@@ -292,7 +289,8 @@ plot_contributions <- function(data, facets = cite_source, bars = cite_label, co
292
289
ggplot2 :: geom_bar() +
293
290
ggplot2 :: labs(y = " Citations" )
294
291
295
- if (! rlang :: quo_is_null(facets )) p <- p + ggplot2 :: facet_grid(cols = ggplot2 :: vars(!! facets ))
292
+ if (! rlang :: quo_is_null(facets )) p <- p + ggplot2 :: facet_wrap(ggplot2 :: vars(!! facets ), nrow = 1 , strip.position = " top" )
293
+
296
294
} else {
297
295
vals <- levels(data %> % dplyr :: select(!! color ) %> % dplyr :: pull() %> % forcats :: as_factor())
298
296
@@ -303,20 +301,37 @@ plot_contributions <- function(data, facets = cite_source, bars = cite_label, co
303
301
dplyr :: summarise(n = dplyr :: n())
304
302
305
303
data_sum $ labelpos <- ifelse(data_sum $ type == vals [1 ],
306
- pmax(.5 * data_sum $ n , 1 + .05 * max(abs(data_sum $ n ))), pmin(- .5 * data_sum $ n , - 1 - .05 * max(abs(data_sum $ n )))
304
+ pmax(.5 * data_sum $ n , 1 + .08 * max(abs(data_sum $ n ))), pmin(- .5 * data_sum $ n , - 1 - .08 * max(abs(data_sum $ n )))
307
305
) # add label positions for geom_text
308
306
307
+ base_size <- 12
308
+ base_theme <- ggplot2 :: theme_minimal(base_size = base_size ) +
309
+ ggplot2 :: theme(
310
+ strip.text = ggplot2 :: element_text(size = 12 ),
311
+ strip.position = " top" ,
312
+ legend.position = " bottom" ,
313
+ legend.title = ggplot2 :: element_text(),
314
+ panel.spacing = ggplot2 :: unit(1 , " lines" ),
315
+ panel.border = ggplot2 :: element_rect(color = " #666666" , fill = NA , linewidth = 0.5 ),
316
+ panel.background = ggplot2 :: element_blank())
317
+
318
+
309
319
p <- ggplot2 :: ggplot(data , ggplot2 :: aes(!! bars , fill = !! color )) +
310
- ggplot2 :: geom_bar(data = data_sum %> % dplyr :: filter(!! color != vals [1 ]), ggplot2 :: aes(y = - .data $ n ), stat = " identity" ) +
311
- ggplot2 :: geom_bar(data = data_sum %> % dplyr :: filter(!! color == vals [1 ]), ggplot2 :: aes(y = .data $ n ), stat = " identity" ) +
312
- ggplot2 :: labs(y = " Citations" ) +
320
+ ggplot2 :: geom_bar(data = data_sum %> % dplyr :: filter(!! color != vals [1 ]), ggplot2 :: aes(y = - .data $ n ), stat = " identity" , alpha = 0.8 ) +
321
+ ggplot2 :: geom_bar(data = data_sum %> % dplyr :: filter(!! color == vals [1 ]), ggplot2 :: aes(y = .data $ n ), stat = " identity" , alpha = 0.8 ) +
322
+ ggplot2 :: labs(y = " Citations" , x = " " ) +
323
+ ggplot2 :: labs(fill = " Citation Type" ) +
324
+ ggplot2 :: scale_fill_manual(values = c(" duplicated" = " lightgrey" , " unique" = " #008080" )) +
313
325
ggplot2 :: scale_y_continuous(labels = abs ) +
326
+ ggplot2 :: geom_hline(yintercept = 0 , color = " white" , linetype = " solid" ) +
314
327
ggplot2 :: guides(x = ggplot2 :: guide_axis(angle = 45 ), fill = ggplot2 :: guide_legend(reverse = TRUE )) +
315
328
# make legend ordering the same as plot ordering
316
- ggplot2 :: geom_text(data = data_sum , ggplot2 :: aes(label = paste0(.data $ n ), y = .data $ labelpos ), size = 3 .5 )
329
+ ggplot2 :: geom_text(data = data_sum , ggplot2 :: aes(label = paste0(.data $ n ), y = .data $ labelpos ), size = 4 .5 ) + base_theme
317
330
318
- if (! rlang :: quo_is_null(facets )) p <- p + ggplot2 :: facet_grid( cols = ggplot2 :: vars(!! facets ))
331
+ if (! rlang :: quo_is_null(facets )) p <- p + ggplot2 :: facet_wrap( ggplot2 :: vars(!! facets ), nrow = 1 , strip.position = " top " )
319
332
}
333
+
334
+
320
335
321
336
if (totals_in_legend == TRUE ) {
322
337
get_total <- function (type ) {
@@ -326,9 +341,8 @@ plot_contributions <- function(data, facets = cite_source, bars = cite_label, co
326
341
327
342
type
328
343
}
329
-
330
- p <- p + ggplot2 :: scale_fill_discrete(labels = scales :: trans_format(" identity" , get_total ))
331
- }
344
+
345
+ p <- p + ggplot2 :: scale_fill_discrete(labels = scales :: trans_format(" identity" , get_total )) }
332
346
333
347
p
334
348
}
0 commit comments