I am wondering whether I can color only certain cells in an R matrix using the
image
command. Currently, I am doing this:
library(Matrix)
args <- commandArgs(trailingOnly=TRUE)
csv_name <- args[1]
pdf_name <- args[2]
pdf(pdf_name)
data <- scan(csv_name, sep=",")
len <- length(data)
num <- sqrt(len)
matrix <- Matrix(data, nrow=num, ncol=num)
image(matrix)
dev.off()
The CSV file contains values between 0 and 1.
Executing the above code gives me the following image:

Now, I want to color in each row the six smallest values red.
Does anyone have an idea how to achieve this?
Thanks in advance,
Sven
Matrix seems to use lattice (levelplot). You can add a layer on top,
Edit: actually, it makes more sense to give the colors in the first place,
but I haven’t succeeded with image:
I may have missed a fine point in the docs…