## play with colorlegend
colorlegend()
colorlegend(side.legend = 2)
colorlegend(side.legend = 2, side.ticks = 2)
colorlegend(height = 2)
colorlegend(width = 1, height = 0.8, scale = FALSE,
pos = c(0, 0.2), length.ticks = 0.5)
colorlegend(color = heat.colors, ncol = 9)
colorlegend(color = heat.colors, ncol = 9, swap = TRUE)
colorlegend(pos = "bottomleft", xpd = TRUE)
colorlegend(pos = "topleft", xpd = TRUE)
colorlegend(pos = "topright", xpd = TRUE)
colorlegend(pos = "bottomright", xpd = TRUE)
## take x values for the color legend
x <- runif(100, -2, 2)
colorlegend(color = diverge_hcl, x = x)
colorlegend(color = diverge_hcl, x = x, at = c(-1.5, 0, 1.5))
colorlegend(color = diverge_hcl, x = x, at = c(-1.5, 0, 1.5),
labels = c("low", "middle", "high"))
colorlegend(color = rainbow_hcl, x = x, at = c(-1.5, 0, 1.5),
labels = c("low", "middle", "high"), length.ticks = 1.5)
colorlegend(color = heat_hcl, x = x, at = c(-1.5, 0, 1.5),
labels = c("low", "middle", "high"), length.ticks = 1.5,
lwd.border = 2, lwd.ticks = 2, cex.labels = 1.5, font = 2)
colorlegend(color = topo.colors, x = x, at = c(-1.5, 0, 1.5),
labels = c("low", "middle", "high"), length.ticks = 1.5,
lwd.border = 2, lwd.ticks = 2, cex.labels = 1.5, font = 2,
col.border = "green3", col.ticks = c(2, 5, 2),
col.labels = c(6, 4, 3))
colorlegend(color = diverge_hsv, x = x, at = c(-1.5, 0, 1.5),
labels = c("low", "middle", "high"), length.ticks = 1.5,
lwd.border = 2, lwd.ticks = 2, cex.labels = 1.5, font = 2,
col.border = "green3", col.ticks = c(2, 5, 2),
col.labels = c(6, 4, 3), lty.border = 2, lty.ticks = c(2, 3, 2))
colorlegend(color = diverge_hsv, x = x, at = c(-1.5, 0, 1.5),
labels = c("low", "middle", "high"), length.ticks = 1.5,
lwd.border = 2, lwd.ticks = 2, cex.labels = 1.5, font = 2,
col.border = "green3", col.ticks = c(2, 5, 2),
col.labels = c(6, 4, 3), lty.border = 2, lty.ticks = c(2, 3, 2),
ncol = 3)
colorlegend(color = c("red", "white", "red"), x = x, at = c(-1.5, 0, 1.5),
labels = c("low", "middle", "high"), length.ticks = 1.5,
lwd.border = 2, lwd.ticks = 2, cex.labels = 1.5, font = 2,
col.border = "green3", col.ticks = c(2, 5, 2),
col.labels = c(6, 4, 3), lty.border = 2, lty.ticks = c(2, 3, 2),
ncol = 3, breaks = c(-2, -1, 1, 2))
colorlegend(color = diverge_hcl, x = x, range = c(-3, 3))
colorlegend(color = diverge_hcl, x = x, range = c(-3, 3), lrange = c(-6, 6))
## combine plot with color legend
n <- 100
x <- y <- seq(-3, 3, length.out = n)
z <- outer(sin(x), cos(x))
pal <- colorlegend(color = diverge_hcl, x = z, plot = FALSE)
op <- par(no.readonly = TRUE)
par(mar = c(5.1, 4.1, 4.1, 6.1))
image(x = x, y = y, z = z, col = pal$colors, breaks = pal$breaks)
colorlegend(color = diverge_hcl, x = z, plot = FALSE, add = TRUE,
xlim = range(x), ylim = range(z), scale = FALSE,
side.legend = 2, side.ticks = 2, pos = c(1.05, -1),
width = diff(range(y)), height = 0.1 * diff(range(x)),
length.ticks = 3, at = seq(min(z), max(z), length.out = 5),
xpd = TRUE)
par(op)
## another example with different plot
n <- 50
x <- sin(seq(-3, 3, length.out = n))
pal <- colorlegend(color = diverge_hcl, x = x, plot = FALSE)
op <- par(no.readonly = TRUE)
barplot(x, border = "transparent", col = pal$map(x))
colorlegend(color = diverge_hcl, x = x, plot = FALSE, add = TRUE,
xlim = c(0, 60), ylim = c(-1, 1), pos = c(0, -0.15), xpd = TRUE,
scale = FALSE, width = 60, height = 0.15, length.ticks = 3,
at = seq(min(x), max(x), length.out = 9))
par(op)Run the code above in your browser using DataLab