Description Usage Arguments Examples
Adding a legend onto a plot
1 |
text |
the string for labels |
pt.cex |
the size of the bubbles |
nbub |
number of bubles to inclued |
xper |
a vector of length two representing the percent of the x axis to start and the percent of the plot to end the the plotting |
yper |
a vector of length two representing the percent of the y axis to start and the percent of the plot to end the the plotting |
sqrt |
Whether the count sizes should be square root transformed |
lims.b |
the limits to be used when scaling the bubble sizes |
bubsize |
The maximum and minimum bubble sizes |
textl |
The number of text characters to in the label |
yspacing |
list of the spacing within the legend, should be length nbub + 1 |
xspacing |
list of the x spacing of the legend, should be length nbub + 1 |
boarder |
the spacing to put around the boarders |
rounddig |
digits to round the number to |
pch |
the character type for the bubles |
pt.bg |
color of the background for the point |
pt.col |
color of the point |
bg |
the background color of the legend |
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 44 45 | ##---- 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 (text, pt.cex, textl = NULL, xper = c(0.6, 0.95), yper = c(0.5,
0.95), yspacing = NULL, xspacing = NULL, boarder = 1, pch = 21,
pt.bg = "blue", pt.col = "black", bg = "blue")
{
nbub <- length(pt.cex)
if (is.null(textl)) {
textl <- max(sapply(text, nchar))
}
if (is.null(yspacing)) {
bs <- pt.cex/2
yspacing <- c(bs, boarder)
yspacing[2:length(yspacing)] <- yspacing[2:length(yspacing)] +
bs
yspacing[1] <- yspacing[1] + boarder
yspacing <- cumsum(yspacing)/sum(yspacing)
yspacing <- yspacing[1:nbub]
}
if (is.null(xspacing)) {
xbub <- c(max(pt.cex))
bs <- xbub/2
xspacing <- c(xbub, textl, boarder)
xspacing[2:length(xspacing)] <- xspacing[2:length(xspacing)] +
bs
xspacing[1] <- xspacing[1] + boarder
xspacing <- cumsum(xspacing)/sum(xspacing)
xspacing <- xspacing[1:2]
}
coords <- par("usr")
xdif <- (coords[2] - coords[1])
ydif <- (coords[4] - coords[3])
xper <- xper * xdif + coords[1]
yper <- yper * ydif + coords[3]
ycoord <- yper[1] + (yper[2] - yper[1]) * yspacing
xcoord <- xper[1] + (xper[2] - xper[1]) * xspacing
rect(xper[1], yper[1], xper[2], yper[2], col = bg)
points(x = rep(xcoord[1], nbub), y = ycoord, cex = pt.cex,
pch = pch, bg = pt.bg, col = pt.col)
text(x = rep(xcoord[2], nbub), y = ycoord, labels = text,
pos = 1, offset = -0.5)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.