画像に凡例を追加するのにimage.plot
使用できます。fields
ここに例があります:
まず、いくつかのデータを生成します:
set.seed(1234)
x<- 1:5; y<- 1:5
z<- matrix(sample(c(1,2,3),25,rep=TRUE),ncol=5,byrow=TRUE)
次に、これを使用して、凡例を追加するfields
通常のパラメーターを使用します。image
# fields
library(fields)
image.plot(x,y,z,col = c("blue" , "red" ,"yellow"),
interpolate=TRUE)

ラスターマトリックスを色のマトリックスに変換したい場合は、次のようにすることができます:
## raster
r <- raster(ncol=5, nrow=5)
values(r) <- z
mm <- matrix(c("blue" , "red" ,"yellow")[values(r)],
ncol=5,byrow=TRUE)
[,1] [,2] [,3] [,4] [,5]
[1,] "blue" "red" "red" "red" "yellow"
[2,] "red" "blue" "blue" "red" "red"
[3,] "yellow" "red" "blue" "yellow" "blue"
[4,] "yellow" "blue" "blue" "blue" "blue"
[5,] "blue" "blue" "blue" "blue" "blue"
image
数値を持つ必要がある色のマトリックスをプロットできないという問題があります。ただし、パッケージgrid.raster
から使用できます:grid
library(grid)
grid.raster(mm,interpolate=FALSE)
編集
axis.args
凡例を手動で修正するには、次の引数で遊ぶことができます plot.image
## fields
image.plot(x,y,z,
col = c("red" , "green" ,"blue"),
axis.args=list( at=0:3, labels=0:3 ))