Description Usage Arguments See Also Examples
View source: R/plotting_functions.R
Allows to mark -Inf, Inf and NA values in heatmaps with different colors. It will automatically detect such values and assign them color.
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",
...
)
|
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 |
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
for function which finally handles heatmap plotting
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.