Description Usage Arguments Value Author(s) See Also Examples
Draw a color ramp of the colors in the current plot.
1 2 |
x,y |
The x and y coordinate of the (non-rotated) upper-left corner of the color ramp. |
width,height |
The width and the height of the (non-rotated) color ramp. |
angle |
The rotation (in degree) of the color ramp. |
borderColor |
The color of the border lines. |
borderType |
The type of the border lines. |
borderWidth |
The width of the border lines. |
xpd |
If |
... |
Other arguments accepted by the |
Returns a list
with x and y coordinates of the corners of the polygons
but also their center coordinates, in the color ramp.
Henrik Bengtsson (http://www.braju.com/R/)
For more information see Color
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # Create data
x <- seq(from=0, to=3*base::pi, length=101)
y <- sin(x)
# Generate colors
y01 <- (y-min(y))/diff(range(y))
col <- RainbowColor(y01)
rampValues <- seq(from=-1,to=1, length=51);
ramp01 <- (rampValues-min(rampValues))/diff(range(rampValues))
ramp <- RainbowColor(ramp01)
# Plot data
opar <- par(mar=c(5,4,4,6)+0.1, xpd=TRUE)
plot(x,y, col=getColors(col), lwd=2)
# Plot color ramp
usr <- par("usr")
dx <- diff(usr[1:2]);
dy <- diff(usr[3:4]);
sh <- 0.05;
# Draw horisontal ramp
drawColorRamp(col, x=usr[1], y=usr[4]+0.01*dy, width=dx, height=sh*dy, angle=0, yadj=0, borderColor=NA)
# Draw vertical ramp
xy <- drawColorRamp(ramp, x=usr[2]+0.01*dx, y=usr[3], width=dy, height=sh*dx, angle=90, xadj=0, borderColor=NA)
incl <- seq(from=1, to=length(rampValues), length=11);
text(xy$below$x[incl], xy$below$y[incl], label=sapply(rampValues[incl], FUN=sprintf, fmt="%+3.2f"), adj=c(-0.1,0.5), cex=0.8)
par(opar)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.