Heatmap.Rd
Generates a heatmap plot.
Heatmap(
score,
color_scheme = c(low = muted("blue"), mid = "white", high = muted("red")),
border_color = NULL,
lab_fill = "score",
angle = 45,
hjust = 1,
vjust = 1,
legend_position = "right",
y_text_position = "right",
feature_text_subset = NULL,
segment.width = c(1, 2.5, 1),
segment.size = 0.2,
text.spacing = 2,
text.size = 2.5,
hide_axis_line = TRUE,
plot.margin = margin(t = 5.5, r = 5.5, b = 5.5, l = 5.5),
expand_limits_x = NULL,
facet_col = NULL,
facet_row = NULL,
panel.spacing = unit(5, "pt"),
strip.placement = "outside",
ncol = NULL,
nrow = NULL,
...
)
A matrix for input, for instance, one generated using the CalcStats function.
Specifies the color gradient for the heatmap visualization. This parameter accepts multiple input formats to provide flexibility in defining color schemes:
- Predefined color schemes: Users can specify "A", "B", "C", "D", or "E" to use color schemes from the `viridis` package.
- Named vector for three-point gradients: Provide a named vector with keys "low", "mid", and "high" to define colors at these specific data points. The "mid" value is typically centered at zero, allowing for a diverging color scheme. Example: `c(low = "blue", mid = "white", high = "red")`
- Two-point gradient: Provide a named vector with keys "low" and "high" to create a simple two-color gradient. Example: `c(low = "blue", high = "red")`
- Custom color gradient: Users can provide a vector of colors to generate a custom gradient across multiple values. This is suitable for more complex data ranges and visual preferences.
Color for the tile borders. Default: NULL.
Label for the color. Default: 'score'.
Angle of the x-axis text. Passed to element_text(). Default: 45.
Horizontal justification of x-axis text. Passed to element_text(). Default: 1.
Vertical justification of x-axis text. Passed to element_text(). Default: 1.
Position of the figure legend. Default: 'right'.
Position of the row name text. Default: 'right'
A subset of feature names to be shown. Useful when there are many features. Default: NULL.
Adjust the width ratio of the line connecting heatmap rows and feature text. Only effective when `feature_text_subset` is set. Default: c(1, 2.5, 1).
Thickness of the line connecting heatmap rows and feature text. Only effective when `feature_text_subset` is set. Default: 0.2.
Spacing between feature texts. Only effective when `feature_text_subset` is set. Default: 2.
Font size of the feature text. Only effective when `feature_text_subset` is set. Default: 2.5.
Whether to hide the axis line or not. Default: TRUE.
Adjusts the space around the plot to prevent text labels from being cut off. This is particularly useful when axis names are too long and may extend beyond the plot boundaries. The margin is defined for top (t), right (r), bottom (b), and left (l) edges of the plot area. To increase the left margin and provide more space for the first name on the x-axis, increase the `l` value. Default: `margin(t = 5.5, r = 5.5, b = 5.5, l = 5.5)` in grid units.
This parameter is softly deprecated in favor of using `plot.margin`. Previously used to increase the space on the left side of the plot by adjusting the x-axis limits. It is still available for backward compatibility but its use is not recommended. Default: NULL.
Vector or factor to split the heatmap columns. Default: NULL.
Vector or factor to split the heatmap rows. Default: NULL.
Spacing between panels when rows or columns are split. Default: unit(5, "pt").
Placement of panel names when rows or columns are split. Default: 'outside'.
Number of columns when either `facet_col` or `facet_row` is not NULL, wrapping the heatmap. Default: NULL.
Number of rows when either `facet_col` or `facet_row` is not NULL, wrapping the heatmap. Default: NULL.
Additional parameters passed to the `theme` function of ggplot2.
A ggplot object.
For more detailed usage, see the examples provided.
# First, create a matrix using the CalcStats function.
genes <- VariableFeatures(pbmc)
toplot <- CalcStats(pbmc, features = genes, method = "zscore", order = "p", n = 5)
# Generate a basic heatmap.
Heatmap(toplot, lab_fill = "zscore")
# Modify the color theme to range from white to dark green.
Heatmap(toplot, lab_fill = "zscore", color_scheme = c("white", muted("green")))
# Use a color theme that transitions from dark blue to light yellow (centered at 0) to dark red.
Heatmap(toplot, lab_fill = "zscore", color_scheme = c(
low = muted("blue"),
mid = "lightyellow",
high = muted("red"))
)
# Employ the viridis color theme, options include A, B, C, D, or E.
Heatmap(toplot, lab_fill = "zscore", color_scheme = "A")
# Adjust the left margin to ensure the x-axis labels fit within the plot boundaries
Heatmap(toplot, lab_fill = "zscore", plot.margin = margin(l = 30))
# Construct a dense matrix with data for 500 genes.
toplot2 <- CalcStats(pbmc, features = genes[1:500], method = "zscore", order = "p")
# Display only a subset of gene names.
Heatmap(toplot2, lab_fill = "zscore", feature_text_subset = genes[1:20], expand_limits_x = c(-0.5, 11))
# Divide the heatmap into rows based on gene groups.
gene_groups <- sample(c("group1", "group2", "group3"), nrow(toplot2), replace = TRUE)
Heatmap(toplot2, lab_fill = "zscore", facet_row = gene_groups) +
theme(axis.text.y = element_blank())