visualize a list of colors/palette in R
As an alternative to the solution using image
you could also use polygon
and create a quite similar plot:
plot(NA, xlim=c(0, nrow(ddf)), ylim=c(0,1))
for (i in 1:nrow(ddf)) {
row <- ddf[i,]
color <- rgb(red=row$r, green=row$g, blue=row$b)
polygon(x=c(i-1, i, i, i-1), y=c(0, 0, 1, 1), col = color)
}
I think the simplest option is scales. This also has the advantage of showing the hex values in the colours.
library(scales)
pal <- rgb(ddf$r, ddf$g, ddf$b)
show_col(pal)
image()
will work well here if you convert the colors via rgb()
image(1:nrow(ddf), 1, as.matrix(1:nrow(ddf)),
col=rgb(ddf$r, ddf$g, ddf$b),
xlab="", ylab = "", xaxt = "n", yaxt = "n", bty = "n")