drawColorRamp.Color: Draw a color ramp of the colors in the current plot

Description Usage Arguments Value Author(s) See Also Examples

Description

Draw a color ramp of the colors in the current plot.

Usage

1
2
## S3 method for class 'Color'
drawColorRamp(this, x, y, width, height, angle=0, xadj=0, yadj=1, borderColor=par("fg"), borderType=par("lty"), borderWidth=par("lwd"), xpd=par("xpd"), ...)

Arguments

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 TRUE, the color ramp can be drawn in the margins too, otherwise not.

...

Other arguments accepted by the polygon function.

Value

Returns a list with x and y coordinates of the corners of the polygons but also their center coordinates, in the color ramp.

Author(s)

Henrik Bengtsson (http://www.braju.com/R/)

See Also

For more information see Color.

Examples

 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)

HenrikBengtsson/R.colors documentation built on May 6, 2019, 11:53 p.m.