Ross Marriott
2013-Apr-03 05:43 UTC
[R] Matrixplot (VIM package): can I add a colour scale?
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)
}
There may be some way to do this using the legend() function?
Thank you.
Regards,
Ross Marriott Ph.D.
Senior Research Scientist
Stock Assessment and Data Analysis
Department of Fisheries WA
Western Australian Fisheries and Marine
Research Laboratories
PO Box 20, North Beach WA 6920, Australia.
Phone: +61 8 9203 0201 (office); 0434604131 (mobile)
Fax: +61 8 9203 0199
Web:
http://www.fish.wa.gov.au<blocked::blocked::blocked::BLOCKED::blocked::http://www.fish.wa.gov.au/>
[[alternative HTML version deleted]]
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