Skip to content

Commit 8d32b7e

Browse files
committed
add label logical
1 parent 4679e3f commit 8d32b7e

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

R/finemap.R

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ finimom_cs_table <- function(finimom_model, df) {
222222
#' @param pos Column name for SNP positions (in base pairs) in `df`.
223223
#' @param p_value Column name for p-values in `df`.
224224
#' @param label Optional vector of SNP IDs (rsIDs) to label in the plot. Default is NULL.
225+
#' @param labels Logical for whether to show text labels for `label` SNPs
225226
#' @param trait Column name for trait or phenotype in `df`. Default is NULL.
226227
#' @param plot_pvalue_threshold Minimum p-value threshold for points to be plotted. Default is 0.1.
227228
#' @param genome_build Genome build version for gene and recombination rate annotations. Default is "GRCh38".
@@ -243,6 +244,7 @@ gg_regionplot <- function(df,
243244
pos,
244245
p_value,
245246
label = NULL,
247+
labels = TRUE,
246248
trait = NULL,
247249
plot_pvalue_threshold = 0.1,
248250
genome_build = "GRCh38",
@@ -318,21 +320,6 @@ gg_regionplot <- function(df,
318320
scale_x_continuous(labels = scales::comma) +
319321
cowplot::theme_cowplot() +
320322

321-
# Add point labels
322-
ggrepel::geom_label_repel(
323-
data = subset(df, rsid %in% label),
324-
aes(label = rsid),
325-
size = 4,
326-
color = "black",
327-
fontface = "bold",
328-
fill = "white",
329-
min.segment.length = 0,
330-
box.padding = 1,
331-
alpha = 1,
332-
max.overlaps = 100,
333-
force = 10
334-
) +
335-
336323
# Add horizontal significance threshold line
337324
geom_hline(yintercept = -log10(5E-8), linetype = "dashed")
338325

@@ -348,6 +335,24 @@ gg_regionplot <- function(df,
348335
) +
349336
theme(axis.title.y.right = element_text(vjust = 1.5))
350337

338+
# Conditionally add ggrepel labels ====
339+
if (labels) {
340+
plot_region <- plot_region +
341+
ggrepel::geom_label_repel(
342+
data = subset(df, rsid %in% label),
343+
aes(label = rsid),
344+
size = 4,
345+
color = "black",
346+
fontface = "bold",
347+
fill = "white",
348+
min.segment.length = 0,
349+
box.padding = 1,
350+
alpha = 1,
351+
max.overlaps = 100,
352+
force = 10
353+
)
354+
}
355+
351356
# Generate the gene plot ====
352357
plot_gene <- gg_geneplot(
353358
chr = unique(df$chromosome),

man/gg_regionplot.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)