[R] Matrixplot (VIM package): can I add a colour scale?

Jim Lemon jim at bitwrit.com.au
Wed Apr 3 13:30:41 CEST 2013


On 04/03/2013 04:43 PM, Ross Marriott wrote:
> Dear R Help,
>
> I would like to know how to add a colour scale to a matrixplot please.
>
> Here is the code that I've used to construct the matrix plot:
>
> library(VIM)
> SpatialPlot<- function(YearxBlock,plot.title){
> # Years are columns, Blocks are rows in this matrix
> YearxBlock<- as.matrix(YearxBlock)
> # To set margins for the plot:
> par(yaxt="n", oma=c(4,4,4,4),mar=c(1.5,1.5,1.5,1.5))
> # Data coded according to a continuous color scheme, with lowest value "light gray", maximum value as "black", missing values as "white":
> matrixplot(YearxBlock,col=c("lightgray","black","white"),axes=FALSE)
> axis(side=1,col="black",at=c(1,4,7,10,13,16,19),
>       labels=as.character(c(1993,1996,1999,2002,2005,2008,2011)),cex.axis=0.8)
> mtext(text="block",side = 2, line = 1, outer = TRUE, font = 1)
> title(main=plot.title,adj=0)
> }
>
Hi Ross,
You can do this with the color.legend function (plotrix).

Jim



More information about the R-help mailing list