Custom colormap for image() in R

Creating a custom colormap in R to plot a matrix is simple:

nsamples <- 20
matrix2plot <- 1:nsamples
dim(matrix2plot) <- c(4, 5)
colors2spaceThrough <- c('red', 'white', 'blue')
customColorMap <- colorRampPalette(colors2spaceThrough)(nsamples)
image(1:4, 1:5, matrix2plot, col = customColorMap)

Continue reading “Custom colormap for image() in R”

Custom colormap for image() in R