1 | gridMapLegend(labs, clrs = NULL, type = "circles")
|
labs |
|
clrs |
|
type |
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 31 32 33 34 35 36 37 38 39 40 41 42 43 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (labs, clrs = NULL, type = "circles")
{
library(grid)
grid.rect(gp = gpar(fill = "white", alpha = 0.7, col = "black"))
n <- length(unique(labs))
if (is.null(clrs))
clrs <- hcl(h = seq(0, 315, length.out = n), c = 60,
l = 50, fixup = TRUE)
if (n == 1)
ypos <- 0.5
else ypos <- seq(0.95, 0.05, length.out = n + 2)
if (n == 1)
ypos <- ypos
else ypos <- ypos[-c(1, length(ypos))]
xpos.pts <- unit(0.1, "npc")
size.pts <- 0.5/n
for (i in 1:n) {
vp <- viewport(x = xpos.pts, y = ypos[i], height = size.pts,
width = 0.1, just = c("left", "centre"))
pushViewport(vp)
switch(type, circles = grid.circle(gp = gpar(fill = clrs[i],
col = "black")), rectangles = grid.rect(gp = gpar(fill = clrs[i],
col = "black")), lines = grid.lines(gp = gpar(col = clrs[i],
lwd = 5)))
upViewport()
}
xpos.txt <- unit(0.25, "npc")
width.txt <- 0.7
for (i in 1:n) {
vp <- viewport(x = xpos.txt, y = ypos[i], height = size.pts,
width = width.txt, just = c("left", "centre"))
pushViewport(vp)
txt <- resizingTextGrob(x = 0, sort(unique(labs))[i],
scale.fact = 2.5, just = "left")
grid.draw(txt)
popViewport()
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.