Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
46 changes: 46 additions & 0 deletions R/00_text_style.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Global text styling shared across every plot in this script. Applied to the
# final patchwork via `& big_helvetica_theme()` so it cascades to every
# sub-panel without rewriting each individual theme() call inside the
# per-plot helpers.

# big_helvetica_theme(): theme() partial that forces every text element to
# Helvetica, plain face (no bold) and a much larger size. Override individual
# pieces with the `base_size` argument.
#
# Example:
# p <- p_lz / p_beta
# p & big_helvetica_theme() # default sizes
# p & big_helvetica_theme(base_size = 22) # even larger
big_helvetica_theme <- function(base_size = 18, family = "Helvetica") {
fam <- family
bs <- as.numeric(base_size)
ggplot2::theme(
text = ggplot2::element_text(family = fam, face = "plain", size = bs),
# Titles are LEFT-aligned (hjust = 0) so a wide title can't overflow into
# the adjacent column when the LocusZoom column is narrower than the
# others. The original ggplot default `hjust = 0.5` re-centres the title
# over its panel and a long title spills sideways into the next panel.
plot.title = ggplot2::element_text(family = fam, face = "plain",
size = bs + 2, hjust = 0,
margin = ggplot2::margin(b = bs * 0.25)),
plot.subtitle = ggplot2::element_text(family = fam, face = "plain",
size = bs - 2, hjust = 0),
# Anchor titles to the whole plot/slot (not just the inner panel) so a
# multi-line title in a narrower column doesn't lean into the neighbour.
plot.title.position = "plot",
plot.caption.position = "plot",
plot.caption = ggplot2::element_text(family = fam, face = "plain", size = bs - 4),
# Axis labels (titles) and tick text are bumped one step above the base
# size so the chromosome / Mb / -log10(P) labels read clearly even when
# the LocusZoom column shares width with the beta / Z panels.
axis.title = ggplot2::element_text(family = fam, face = "plain", size = bs + 3),
axis.title.x = ggplot2::element_text(family = fam, face = "plain", size = bs + 3),
axis.title.y = ggplot2::element_text(family = fam, face = "plain", size = bs + 3),
axis.text = ggplot2::element_text(family = fam, face = "plain", size = bs + 2),
axis.text.x = ggplot2::element_text(family = fam, face = "plain", size = bs + 2),
axis.text.y = ggplot2::element_text(family = fam, face = "plain", size = bs + 2),
legend.title = ggplot2::element_text(family = fam, face = "plain", size = bs - 2),
legend.text = ggplot2::element_text(family = fam, face = "plain", size = bs - 4),
strip.text = ggplot2::element_text(family = fam, face = "plain", size = bs)
)
}
11 changes: 9 additions & 2 deletions R/10_plot_ref.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ plot_ref <- function(df, title_text, join_col, pt_size, use_raster) {
}
p + scale_color_identity() +
geom_text_repel(data = centroids, aes(label = .data[[join_col]]),
size = 3.5, fontface = "bold", bg.color = "white",
family = "Helvetica", fontface = "plain",
size = 6, bg.color = "white",
bg.r = 0.1, min.segment.length = 0) +
# UMAP dimensions carry no numeric meaning -- remove breaks at the scale
# level so the global theme cascade can't reintroduce tick labels.
scale_x_continuous(breaks = NULL) +
scale_y_continuous(breaks = NULL) +
coord_equal() + labs(title = title_text, x = NULL, y = NULL) +
theme_minimal() +
theme(panel.grid = element_blank(), axis.text = element_blank(),
theme(panel.grid = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
plot.title = element_text(face = "bold"))
}
22 changes: 17 additions & 5 deletions R/11_plot_beta.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,22 @@ plot_beta <- function(df, title, pt_size, join_col, show_legend = TRUE,
}

p <- p + scale_color_gradientn(colors = colors_beta,
limits = c(-b_max, b_max), na.value = "grey50",
limits = c(-b_max, b_max), na.value = "#dadada",
name = "Beta",
values = c(0.0, 0.20, 0.45, 0.5, 0.55, 0.80, 1.0)) +
coord_equal() + labs(title = title, x = NULL, y = NULL) + theme_minimal() +
theme(panel.grid = element_blank(), axis.text = element_blank(),
# UMAP_1 / UMAP_2 axes carry no numeric meaning, so remove their breaks
# at the SCALE level. Doing it via theme(axis.text = element_blank())
# alone is not enough because the outer `& big_helvetica_theme()`
# cascade later overrides axis.text and resurrects the tick labels.
scale_x_continuous(breaks = NULL) +
scale_y_continuous(breaks = NULL) +
# `clip = "off"` lets the ggrepel cell-type centroid labels draw past
# the panel edge -- at the bigger Helvetica size they sometimes start
# near the panel boundary and get truncated (e.g. "T_CD4_C" instead of
# "T_CD4_CM").
coord_equal(clip = "off") + labs(title = title, x = NULL, y = NULL) + theme_minimal() +
theme(panel.grid = element_blank(),
axis.text = element_blank(), axis.ticks = element_blank(),
plot.title = element_text(size = 8.5, face = "bold"),
legend.title = element_text(size = 12, face = "bold"),
legend.text = element_text(size = 10))
Expand All @@ -59,8 +70,9 @@ plot_beta <- function(df, title, pt_size, join_col, show_legend = TRUE,
}
p <- p + geom_text_repel(data = centroids,
aes(x = UMAP_1, y = UMAP_2, label = label_text),
inherit.aes = FALSE, size = 4.5,
fontface = "bold", bg.color = "white", bg.r = 0.15,
inherit.aes = FALSE, size = 7.5,
family = "Helvetica", fontface = "plain",
bg.color = "white", bg.r = 0.15,
color = "black", min.segment.length = 0)
}
return(p)
Expand Down
2 changes: 1 addition & 1 deletion R/12_plot_zscore.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ plot_zscore_df <- function(df, title = "Coloc Z-Scores", panel_cs_label = NULL)
geom_abline(slope = 1, intercept = 0, color = "gray80", linetype = "dotted") +
geom_abline(slope = -1, intercept = 0, color = "gray80", linetype = "dotted") +
geom_point(fill = "#1E90FF", color = "white", shape = 21,
size = 2.5, alpha = 0.8, stroke = 0.3) +
size = 3.5, alpha = 0.8, stroke = 0.3) +
coord_fixed(xlim = c(-limit_val, limit_val), ylim = c(-limit_val, limit_val)) +
theme_minimal() +
labs(title = title, x = "QTL Z-Score", y = "Disease Z-Score") +
Expand Down
10 changes: 7 additions & 3 deletions R/13_plot_zoom.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ plot_zoom_annotations <- function(anno_win, chr_label, lead_pos, win_half,
} else {
p <- p + annotate("text", x = lead_pos, y = (n_tracks + 1) / 2,
label = "No annotations in window",
size = 3.2, color = "gray55", fontface = "italic")
family = "Helvetica", fontface = "italic",
size = 5, color = "gray55")
}
# Row guides on top of rects so each bar lines up with its y-axis label.
p <- p + geom_hline(yintercept = seq_len(n_tracks), colour = "gray58",
Expand Down Expand Up @@ -208,7 +209,8 @@ build_merged_zoom_box <- function(chr_label, lead_positions,
p <- p + annotate("text",
x = mean(lead_positions), y = (n_tracks + 1) / 2,
label = "No annotations in merged window",
size = 3.2, color = "gray55", fontface = "italic")
family = "Helvetica", fontface = "italic",
size = 5, color = "gray55")
}
p <- p + geom_hline(yintercept = seq_len(n_tracks), colour = "gray58",
linewidth = 0.2, alpha = 0.88)
Expand Down Expand Up @@ -236,7 +238,9 @@ build_merged_zoom_box <- function(chr_label, lead_positions,
alpha = 0.95, linewidth = 0.7)
p <- p + geom_text_repel(data = extra_df,
aes(x = lead, y = n_tracks + 1.3, label = label),
color = "#BF4F00", size = 2.7, fontface = "bold",
color = "#BF4F00",
family = "Helvetica", fontface = "plain",
size = 5,
direction = "y", nudge_y = 0.2,
segment.size = 0.3, segment.alpha = 0.6,
box.padding = 0.25, point.padding = 0.1,
Expand Down
Loading