# gggenomes' options for representing the x-axis scaling are:
library(patchwork) # to combine plots in same figure
# 1. The default `axis_scalebar` with short ...
p1 <- gggenomes(genes = emale_genes) |> pick(1:2) + # two short genomes
geom_seq() + geom_gene()
# ... and with long sequences; some simple styling ...
s0 <- tibble::tibble(
seq_id = c("a", "b", "b"),
length = c(2000000, 500000, 1000000))
q0 <- gggenomes(seqs = s0) + geom_seq()
q1 <- q0 + axis_scalebar(length = 0.1, fontface = "bold")
# ... or more advanced styling, ...
p2 <- p1 + axis_scalebar(length = 3333, label_position = "below",
linewidth = 0.6, tick_height = c(1,6))
# ... down to theme and guide customization
q2 <- q1 +
theme_scalebar(text_size = 8, color = "red") +
guides(
x = guide_scalebar(just = "left", label = \(x){paste(x, "nucleotides")}))
p1 + q1 + p2 + q2 + plot_layout(ncol=2)
# 2. The optional `geom_scalebar` with easy relative ...
p3 <- p1 + geom_scalebar(x = "center", y = 0.5)
# ... and absolute placement anywhere in the plot area
q3 <- q1 + geom_scalebar(length = 0.1, x = 1.5e6, y = 1.3, color = "blue",
fontface = "italic")
# 3. Or also a regular axis with genomic units...
p4 <- p1 + guides(x = "axis")
# ... which can be further customized
q4 <- q0 + scale_x_genomic(guide = "axis", unit = "", sep = "")
p3 + q3 + p4 + q4 + plot_layout(ncol=2)
# Note: `xlim()` or scale_x_continuous()` will overwrite the genomic scale
p1 + xlim(c(0, 1e4)) +
# Use `scale_x_genomic(limits=)` to prevent that
p1 + scale_x_genomic(limits=c(0, 1e4))
Run the code above in your browser using DataLab