Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot a vector of colors in R

Tags:

plot

r

I have this vector of colours in R:

"#88FF00" "#54FF00" "#FFFF00" "#13FF00" "#50FF00" "#87FF00" "#FDFB02" "#B8FF00" "#6DFF00" 
"#ECFF00" "#CBFF00" "#EDFF00" "#39FF00" "#B7FF00" "#75FF00" "#65FF00" "#C2FF00" "#25FF00" 
"#9AFF00" "#E6FF00" "#58FF00" "#E5CA1A" "#DEFF00" "#9AFF00" "#21FF00" "#35FF00" "#3AFF00" 
"#D0912F" "#FF0000" "#F7EF08" "#40FF00" "#DA7325" "#D8B027" "#DAFF00" "#55FF00" "#F8F007"
"#46FF00" "#69FF00" "#B8FF00" "#37FF00" "#32FF00" "#60FF00" "#7CFF00" "#00FF00" "#50FF00" 
"#F3E60C" "#DFBE20" "#7FFF00" "#F7EF08" "#99FF00" "#13FF00" "#DA7325" "#13FF00"

And I want to plot them in this order, something such as a heatmap. I had been toying with the image function but the colours are reordered and even modified by the image function.

The code that I tried is the following, when cols is the vector of colors mentioned above:

  image(1:nrow(expressionOrdered), 1:ncol(expressionOrdered), as.matrix(expressionOrdered), col= cols,xlab="",ylab="")
like image 712
Dani Avatar asked Sep 11 '25 20:09

Dani


1 Answers

How about just a bunch of rectangles?

COL = c("#88FF00", "#54FF00", "#FFFF00", "#13FF00", 
"#50FF00", "#87FF00", "#FDFB02", "#B8FF00", "#6DFF00", 
"#ECFF00", "#CBFF00", "#EDFF00", "#39FF00", "#B7FF00", 
"#75FF00", "#65FF00", "#C2FF00", "#25FF00", "#9AFF00", 
"#E6FF00", "#58FF00", "#E5CA1A", "#DEFF00", "#9AFF00", 
"#21FF00", "#35FF00", "#3AFF00", "#D0912F", "#FF0000", 
"#F7EF08", "#40FF00", "#DA7325", "#D8B027", "#DAFF00", 
"#55FF00", "#F8F007", "#46FF00", "#69FF00", "#B8FF00", 
"#37FF00", "#32FF00", "#60FF00", "#7CFF00", "#00FF00", 
"#50FF00", "#F3E60C", "#DFBE20", "#7FFF00", "#F7EF08", 
"#99FF00", "#13FF00", "#DA7325", "#13FF00")

plot(NULL, xlim=c(0,length(COL)), ylim=c(0,1), 
    xlab="", ylab="", xaxt="n", yaxt="n")
rect(0:(length(COL)-1), 0, 1:length(COL), 1, col=COL)

Rectangles

like image 55
G5W Avatar answered Sep 13 '25 09:09

G5W