image_plot_na: Wrapper for fields::image.plot function.

Description Usage Arguments See Also Examples

View source: R/plotting_functions.R

Description

Allows to mark -Inf, Inf and NA values in heatmaps with different colors. It will automatically detect such values and assign them color.

Usage

1
2
3
4
5
6
7
8
9
image_plot_na(
  z,
  breaks,
  col,
  na.color = "black",
  neg.inf.color = "gold",
  pos.inf.color = "darkgreen",
  ...
)

Arguments

z

numeric matrix to be plotted; may contain -Inf, Inf and NA values

breaks

numeric vector of breaks for colorscale

col

character vector of hex color strings; usually generated from some color pallette; it's length must be equal to length(breaks) - 1

na.color

color for NA values

neg.inf.color

color for -Inf values

pos.inf.color

color for Inf values

...

additional arguments passed to image.plot

See Also

image.plot for function which finally handles heatmap plotting

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# matrix of data
mtx <- toeplitz(c(5:1))
# make lower triangle part negative
mtx[lower.tri(mtx)] <- -mtx[lower.tri(mtx)]
# make some cells -Inf
mtx[matrix(c(2,1,2,2,3,2), ncol = 2, byrow = TRUE)] <- -Inf
# make some cells Inf
mtx[matrix(c(3,5,4,5), ncol = 2, byrow = TRUE)] <- Inf
# make some cells NA
mtx[matrix(c(1,3,2,3,5,3), ncol = 2, byrow = TRUE)] <- NA
print(mtx)
# prepare breaks --> symmetric, from -5 to 5, spaced by 2, with 0 in the middle
# one can also introduce here log, sqrt or other scales by applying proper transformations
breaks <- sort(c(0,seq(-5,5,2)))
print(breaks)
# prepare symmetric color pallette indicating negtive values with blue, middle with white and positive with red
colors.pal = c("blue","white","red")
pal = colorRampPalette(colors.pal)
colors <- pal(length(breaks) - 1L)
# finally plot matrix
image_plot_na(mtx, breaks, colors)

rz6/CopulaHiC documentation built on Dec. 31, 2019, 9:19 a.m.