Search code examples
rcolorsfillr-grid

draw color scale in grid plot in r


I want to plot color scale with grid package. Something like heat.plot (10).

enter image description here

I am trying something like this:

require(grid)
legendViewport <- viewport(height=0.3, width=0.8)
pushViewport(legendViewport)
grid.rect(gp = gpar(col = "gray90"))

Let's say I want to divide 0 to 1, into 10 and fill heat.colors (10). Is there a simple way to do it.


Solution

  • If you just want colors,

    grid.raster(t(heat.colors (10)), 
       width=unit(1,"npc"),
       height=unit(1,"npc"), int=FALSE)