imageScale | R Documentation |
The imageScale
function is wrapper for imageScale
and accepts the same arguments. It converts a vector of values (z
) to a vector of color levels. One must define the number of colors. The limits of the color scale ("zlim") or the break points for the color changes("breaks") can also be defined. When breaks and zlim are defined, breaks overrides zlim. All arguments are similar to those in the image
function. Appearance is best when incorporated with layout
.
imageScale(z, zlim, col = heat.colors(12), breaks, axis.pos = 1, add.axis = TRUE, xlim = NULL, ylim = NULL, log, ...)
z |
A vector or matrix of values. |
zlim |
Limits of the color scale values. |
col |
Vector of color values (default is 12 colors
from the |
breaks |
Break points for color changes. If breaks is specified then |
axis.pos |
Position of the axis (1=bottom, 2=left, 3=top, 4=right) (default = 1). |
add.axis |
Logical (TRUE/FALSE). Defines whether the axis is added (default: TRUE). |
xlim |
Limits for the x-axis. |
ylim |
Limits for the y-axis. |
log |
logical. If |
... |
Additional graphical parameters to pass to the |
Marc Taylor, modified for log scale by Héctor Villalobos
# Make color palettes pal.1=colorRampPalette(c("green4", "orange", "red", "white"), space="rgb", bias=0.5) pal.2=colorRampPalette(c("blue", "cyan", "yellow", "red", "pink"), space="rgb") # Make images with corresponding scales op <- par(no.readonly = TRUE) 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,0,1)) imageScale(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,0,1,3)) imageScale(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) par(op)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.