Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep same colour scale between image plots (R)

Tags:

r

colors

I'm generating multiple plots with command image

image(X,Y,MAT,col=heat.colors(100))

this command is in a for cycle, where X, Y and MAT change.

How can I have the same colour scale for all the plots (I have to compre them)? How can I set a common colour scale (I have the maximum and minimum value beteen all plots)?

Thanks

like image 592
Darko Avatar asked Dec 31 '25 04:12

Darko


1 Answers

Feed the overall maximum and minimum values of MAT over all loop iterations into the zlim parameter of image.

set.seed(1)
xx <- sort(rnorm(10))
yy <- sort(rnorm(10))
zz <- list(matrix(rnorm(100),nrow=10,ncol=10),matrix(rnorm(100)-2,nrow=10,ncol=10))
par(mfrow=c(1,2))
image(xx,yy,z=zz[[1]],col=heat.colors(100))
image(xx,yy,z=zz[[2]],col=heat.colors(100))

plot 1

image(xx,yy,z=zz[[1]],col=heat.colors(100),zlim=range(unlist(zz)))
image(xx,yy,z=zz[[2]],col=heat.colors(100),zlim=range(unlist(zz)))

plot 2

like image 74
Stephan Kolassa Avatar answered Jan 01 '26 17:01

Stephan Kolassa