Created
December 5, 2013 11:26
-
-
Save menugget/7803814 to your computer and use it in GitHub Desktop.
An example of the use of the image.scale function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(devtools) | |
source_url('https://gist.github.com/menugget/7689145/raw/dac746aa322ca4160a5fe66c70fec16ebe26faf9/image.scale.2.r') | |
png("volcano_w_scale.png", width=7, height=4, units="in", res=200) | |
layout(matrix(c(1,2,3,0,4,0), nrow=2, ncol=3), widths=c(4,4,1), heights=c(4,1)) | |
layout.show(4) | |
#1st image | |
breaks <- seq(min(volcano), max(volcano),length.out=100) | |
par(mar=c(1,1,1,1)) | |
image(seq(dim(volcano)[1]), seq(dim(volcano)[2]), volcano, | |
col=pal.1(length(breaks)-1), breaks=breaks-1e-8, xaxt="n", yaxt="n", ylab="", xlab="") | |
#Add additional graphics | |
levs <- pretty(range(volcano), 5) | |
contour(seq(dim(volcano)[1]), seq(dim(volcano)[2]), volcano, levels=levs, add=TRUE) | |
#Add scale | |
par(mar=c(3,1,1,1)) | |
image.scale(volcano, col=pal.1(length(breaks)-1), breaks=breaks-1e-8,axis.pos=1) | |
abline(v=levs) | |
box() | |
#2nd image | |
breaks <- c(0,100, 150, 170, 190, 200) | |
par(mar=c(1,1,1,1)) | |
image(seq(dim(volcano)[1]), seq(dim(volcano)[2]), volcano, | |
col=pal.2(length(breaks)-1), breaks=breaks-1e-8, xaxt="n", yaxt="n", ylab="", xlab="") | |
#Add additional graphics | |
levs=breaks | |
contour(seq(dim(volcano)[1]), seq(dim(volcano)[2]), volcano, levels=levs, add=TRUE) | |
#Add scale | |
par(mar=c(1,1,1,3)) | |
image.scale(volcano, col=pal.2(length(breaks)-1), breaks=breaks-1e-8, axis.pos=4, add.axis=FALSE) | |
axis(4,at=breaks, las=2) | |
box() | |
abline(h=levs) | |
dev.off() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment