Skip to content

Commit 09e1d75

Browse files
committed
aesthetic plot changes
1 parent 270e01c commit 09e1d75

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

R/plots.R

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,21 @@ plot_source_overlap_heatmap <- function(data, cells = "source", facets = NULL, p
101101
ggplot2::theme(
102102
aspect.ratio = 1, legend.position = "none",
103103
strip.background = ggplot2::element_rect(
104-
color = "black", fill = "darkgrey"
104+
color = "black", fill = "#3A3A3A"
105105
)
106-
) + ggplot2::scale_fill_gradient(low = "white")
106+
) + ggplot2::scale_fill_gradient(low = "white", high = "#23395B")
107107
# Removed legends here because they do not appear in correct order - maybe worth fixing in the future
108108
facets <- unique(data$facet)
109109

110110
for (i in seq_along(facets)) {
111111
p <- p + ggnewscale::new_scale_fill() + ggplot2::geom_tile(ggplot2::aes(fill = .data$records), data = data %>% dplyr::filter(.data$facet == facets[i])) +
112112

113-
ggplot2::scale_fill_gradient(low = "white")
113+
ggplot2::scale_fill_gradient(low = "white", high = "#008080")
114114
}
115115
} else {
116116
p <- p +
117117
ggplot2::geom_tile() +
118-
ggplot2::scale_fill_gradient(low = "white")
118+
ggplot2::scale_fill_gradient(low = "white", high = "#008080")
119119
}
120120

121121
p +
@@ -153,7 +153,7 @@ plot_source_overlap_heatmap <- function(data, cells = "source", facets = NULL, p
153153
dplyr::mutate(dplyr::across(dplyr::starts_with("DB"), ~ stringr::str_remove(.x, paste0(cells, "__")))) %>%
154154
ggplot2::ggplot(ggplot2::aes(.data$DB1, .data$DB2, fill = .data$shares)) +
155155
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)) +
157157
ggplot2::geom_text(ggplot2::aes(label = fmt_pct(.data$shares), fill = NULL)) +
158158
ggplot2::labs(
159159
x = "", y = "", fill = "Overlap",
@@ -162,18 +162,12 @@ plot_source_overlap_heatmap <- function(data, cells = "source", facets = NULL, p
162162
) +
163163
ggplot2::scale_x_discrete(limits = rev(sources_order), guide = ggplot2::guide_axis(angle = 45)) +
164164
ggplot2::scale_y_discrete(limits = sources_order) +
165-
ggplot2::theme_light()
166165

167166

168167

169168
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+
177171
}
178172
p
179173
}
@@ -219,11 +213,14 @@ plot_source_overlap_upset <- function(data, groups = "source", nsets = NULL, set
219213
}
220214

221215
if (nsets > 5) message("Plotting a large number of groups. Consider reducing nset or sub-setting the data.")
222-
216+
223217
data %>%
224218
data.frame() %>%
225219
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, ...)
227224
}
228225

229226
# Hack to suppress check warning re default values below
@@ -292,7 +289,8 @@ plot_contributions <- function(data, facets = cite_source, bars = cite_label, co
292289
ggplot2::geom_bar() +
293290
ggplot2::labs(y = "Citations")
294291

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+
296294
} else {
297295
vals <- levels(data %>% dplyr::select(!!color) %>% dplyr::pull() %>% forcats::as_factor())
298296

@@ -303,20 +301,37 @@ plot_contributions <- function(data, facets = cite_source, bars = cite_label, co
303301
dplyr::summarise(n = dplyr::n())
304302

305303
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)))
307305
) # add label positions for geom_text
308306

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+
309319
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")) +
313325
ggplot2::scale_y_continuous(labels = abs) +
326+
ggplot2::geom_hline(yintercept = 0, color = "white", linetype = "solid") +
314327
ggplot2::guides(x = ggplot2::guide_axis(angle = 45), fill = ggplot2::guide_legend(reverse = TRUE)) +
315328
# 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
317330

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")
319332
}
333+
334+
320335

321336
if (totals_in_legend == TRUE) {
322337
get_total <- function(type) {
@@ -326,9 +341,8 @@ plot_contributions <- function(data, facets = cite_source, bars = cite_label, co
326341

327342
type
328343
}
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)) }
332346

333347
p
334348
}

0 commit comments

Comments
 (0)