This function creates a continuous fill scale optimized for Hi-C contact matrix visualization. It provides common color palettes and supports log transformations.
Arguments
- palette
Character string specifying the color palette. Options: "cooler" (red gradient, default), "ylgnbu" (yellow-green-blue), "viridis", or "bwr" (blue-white-red for diverging data)
- trans
Transformation for the scale. Options: "identity" (linear, default), "log10", "log2", "sqrt". Can also pass a transformation object.
- limits
Numeric vector of length 2 giving the scale limits. Values outside this range will be squished to the nearest limit. Default: NULL (auto)
- na.value
Color for missing values (default: "grey50")
- midpoint
For diverging palettes ("bwr"), the midpoint value (default: 0)
- oob
Function to handle out-of-bounds values. Default: scales::squish
- ...
Additional arguments passed to ggplot2::scale_fill_gradientn or scale_fill_gradient2
Examples
if (FALSE) { # \dontrun{
library(ggplot2)
# Basic usage with default cooler palette
ggplot(hic_data, aes(x = x, y = y, fill = score)) +
geom_hic() +
scale_fill_hic()
# Log10 transformation
ggplot(hic_data, aes(x = x, y = y, fill = score)) +
geom_hic() +
scale_fill_hic(trans = "log10")
# Different palette with limits
ggplot(hic_data, aes(x = x, y = y, fill = score)) +
geom_hic() +
scale_fill_hic(palette = "ylgnbu", limits = c(0, 100))
# Diverging palette for comparison data
ggplot(diff_data, aes(x = x, y = y, fill = log2fc)) +
geom_hic() +
scale_fill_hic(palette = "bwr", midpoint = 0)
} # }