Draws copy number segments as thin horizontal bars at their integer copy number, as
in gTrack. xmin, xmax, and y default to the start, end, and total_cn
columns, as in JaBbA copy number profiles; map y to another column such as
major_allele to change it. Segments are filled by their integer copy number with
scale_fill_copynumber() unless fill is mapped or set, e.g. by state with
aes(fill = cn_state) and scale_fill_cn_state(). Bars use fill so colour stays
free for geom_junction() in the same plot.
Segments above cn_cap are drawn at the cap and marked with a triangle, so a few
highly amplified segments do not flatten the rest of the profile. Adjacent segments
are joined by thin gray reference connectors, as in JaBbA genome graphs.
With alleles, the major and minor allele copy numbers are drawn as two
semi-transparent series, red and blue, so where they are equal the bars overlap in
purple.
Also adds a y-axis scale with whole-number breaks starting at zero and a
"Copy Number" y-axis title. Add your own scale_y_continuous() or labs() after it
to override them.
Usage
geom_copy_number(
mapping = NULL,
data = NULL,
cn_cap = NULL,
bar_height = 1.5,
connectors = TRUE,
alleles = NULL,
show_first_y_label = TRUE,
...,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)Arguments
- mapping
Set of aesthetic mappings created by
ggplot2::aes(), e.g.fill.- data
GRanges object or data frame of copy number segments with
seqnames,start,end, andtotal_cncolumns, e.g. a JaBbAcnv.bedprofile.- cn_cap
Highest copy number shown, default: no cap. Segments above it are drawn at the cap with a triangle marker.
- bar_height
Height of the bars in mm, default: 1.5
- connectors
Join adjacent segments with thin gray lines, default: TRUE. Segments are assumed to come from one sample per layer.
- alleles
Draw allele-specific copy number instead of total copy number, by giving the major and minor allele columns, e.g.
c("major_allele", "minor_allele"), orTRUEfor those JaBbA column names. Default:NULLfor total copy number.- show_first_y_label
Label the lowest y-axis break, default: TRUE. See
label_drop_first().- ...
Other arguments passed to
ggplot2::layer(), e.g.fill,colour(bar outline), oralpha.- na.rm, show.legend, inherit.aes
See
ggplot2::layer().
Value
List of a ggplot2 layer, a y-axis scale, a y-axis title, and a copy number
fill scale unless fill is given, added to a plot with +
Examples
if (FALSE) { # \dontrun{
cn <- data.table::fread("sample.jabba.phased.cnv.bed")
data.table::setnames(cn, "chrom", "seqnames")
ggplot2::ggplot(cn) +
geom_copy_number(cn_cap = 8) +
coord_genome() +
theme_genomic()
} # }
