Custom axis for image.plot() from fields package
It was a bug in R that has been corrected in r-devel (r72982). Thanks to Paul Murrell <paul@stat.auckland.ac.nz>
______________________________________
For an obscur reason, it is not possible to customize axes of the "big plot" done with image.plot() from package fields:
library(fields)
par(mar=c(5,4.5,4,7))
D <- matrix(c(10, 20, 25, 30, 12, 22, 32, 35, 13, 25, 38, 40), nrow=3)
image.plot(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
ylab="Columns", cex.lab = 0.5, zlim=c(min(D, na.rm=TRUE),max(D, na.rm=TRUE)),
las=1, axes=FALSE)
axis(1, at=seq(from=0, to=1, length=nrow(D)), labels=0:2, cex.axis=0.5)
axis(2, at=seq(from=0, to=1, length=ncol(D)), labels=0:3, las=1, cex.axis=0.5)
First solution: plot separately the heatmap and the legend:
image(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
ylab="Columns", cex.lab = 0.5, zlim=c(min(D, na.rm=TRUE),max(D, na.rm=TRUE)),
las=1, axes=FALSE)
axis(1, at=seq(from=0, to=1, length=nrow(D)), labels=0:2, cex.axis=0.5)
axis(2, at=seq(from=0, to=1, length=ncol(D)), labels=0:3, las=1, cex.axis=0.5)
image.plot(D, col=rev(heat.colors(128)), zlim=c(min(D, na.rm=TRUE),max(D, na.rm=TRUE)),
legend.only=TRUE)
Second solution, insert a point out the of plotting region:
image.plot(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
ylab="Columns", cex.lab = 0.5, zlim=c(min(D, na.rm=TRUE),max(D, na.rm=TRUE)),
las=1, axes=FALSE)
points(1.5, 1.5, type="p")
axis(1, at=seq(from=0, to=1, length=nrow(D)), labels=0:2, cex.axis=0.5)
axis(2, at=seq(from=0, to=1, length=ncol(D)), labels=0:3, las=1, cex.axis=0.5)
______________________________________
For an obscur reason, it is not possible to customize axes of the "big plot" done with image.plot() from package fields:
library(fields)
par(mar=c(5,4.5,4,7))
D <- matrix(c(10, 20, 25, 30, 12, 22, 32, 35, 13, 25, 38, 40), nrow=3)
image.plot(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
ylab="Columns", cex.lab = 0.5, zlim=c(min(D, na.rm=TRUE),max(D, na.rm=TRUE)),
las=1, axes=FALSE)
axis(1, at=seq(from=0, to=1, length=nrow(D)), labels=0:2, cex.axis=0.5)
axis(2, at=seq(from=0, to=1, length=ncol(D)), labels=0:3, las=1, cex.axis=0.5)
First solution: plot separately the heatmap and the legend:
image(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
ylab="Columns", cex.lab = 0.5, zlim=c(min(D, na.rm=TRUE),max(D, na.rm=TRUE)),
las=1, axes=FALSE)
axis(1, at=seq(from=0, to=1, length=nrow(D)), labels=0:2, cex.axis=0.5)
axis(2, at=seq(from=0, to=1, length=ncol(D)), labels=0:3, las=1, cex.axis=0.5)
image.plot(D, col=rev(heat.colors(128)), zlim=c(min(D, na.rm=TRUE),max(D, na.rm=TRUE)),
legend.only=TRUE)
Second solution, insert a point out the of plotting region:
image.plot(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
ylab="Columns", cex.lab = 0.5, zlim=c(min(D, na.rm=TRUE),max(D, na.rm=TRUE)),
las=1, axes=FALSE)
points(1.5, 1.5, type="p")
axis(1, at=seq(from=0, to=1, length=nrow(D)), labels=0:2, cex.axis=0.5)
axis(2, at=seq(from=0, to=1, length=ncol(D)), labels=0:3, las=1, cex.axis=0.5)
Commentaires
Enregistrer un commentaire