add_labels: Add Text Labels to a ggplot

View source: R/add_labels.R

add_labelsR Documentation

Add Text Labels to a ggplot

Description

Add text labels to a ggplot object, such as the result from show_sig_profile.

Usage

add_labels(
  p,
  x,
  y,
  y_end = NULL,
  n_label = NULL,
  labels = NULL,
  revert_order = FALSE,
  font_size = 5,
  font_family = "serif",
  font_face = c("plain", "bold", "italic"),
  ...
)

Arguments

p

a ggplot.

x

position at x axis.

y

position at y axis.

y_end

end position of y axis when n_label is set.

n_label

the number of label, when this is set, the position of labels at y axis is auto-generated according to y and y_end.

labels

text labels or a similarity object from get_sig_similarity.

revert_order

if TRUE, revert label order.

font_size

font size.

font_family

font family.

font_face

font face.

...

other parameters passing to ggplot2::annotate.

Value

a ggplot object.

Examples

# Load mutational signature
load(system.file("extdata", "toy_mutational_signature.RData",
  package = "sigminer", mustWork = TRUE
))
# Show signature profile
p <- show_sig_profile(sig2, mode = "SBS")

# Method 1
p1 <- add_labels(p,
  x = 0.75, y = 0.3, y_end = 0.9, n_label = 3,
  labels = paste0("text", 1:3)
)
p1

# Method 2
p2 <- add_labels(p,
  x = c(0.15, 0.6, 0.75), y = c(0.3, 0.6, 0.9),
  labels = paste0("text", 1:3)
)
p2

# Method 3
sim <- get_sig_similarity(sig2)
p3 <- add_labels(p,
  x = c(0.15, 0.6, 0.75), y = c(0.25, 0.55, 0.8),
  labels = sim, font_size = 2
)
p3

sigminer documentation built on May 29, 2024, 3:11 a.m.