makeNiceLegend | R Documentation |
Draws a legend in the margins based on factor levels.
makeNiceLegend(
labels,
title = "Legend",
fontCol = "black",
border = NULL,
lineCol = NA,
bg = NA,
col = makeColorMatrix()[, 3],
shape = "c",
size = 0.75,
spacing = 0.2,
fontFamily = "sans",
sizeScale = NA,
shapeScale = NA,
scaleDefaultColor = "black"
)
labels |
character vector; The names of the levels describe in the legend. Typically factor levels. |
title |
character; The title of the legend. This defaults to "Legend" if unspecified. |
fontCol |
R color; Color of the legend text. |
border |
R color; The color of the rectangular border surrounding the legend. Defaults to |
lineCol |
R color; The color of the line colors for the color key. Optional. Defaults to |
bg |
R color; Sets the background color for the legend area. Note that this can be distinct the the margin background. |
col |
R color vector; A vector of colors determining the color of the color code boxes. |
shape |
character; Determines what kind of legend to draw. "c" is colors - colored rectangle default; "s" is point shape (pch); "z" is size scaling (cex). These can be combined so a color and point shape together is "cs". |
size |
numeric; Sets the overall legend font cex sizing. |
spacing |
numeric; Determines the total amount of padding (sum of upper and lower padding) surrounding each line. in the legend in units of font line height. |
fontFamily |
character; font family used for string height calculations. Possible values are "sans", "mono", or "serif" |
sizeScale |
numeric; This is the cex values for size scaling legends. |
shapeScale |
numeric; This is the pch value for legends including point shape. |
scaleDefaultColor |
color; This is the color shape and size indicators will be if they are not linked to a color scale. Defaults to black. |
This functions works with plot environment initializing functions such as prepCategoryWindow
to expand the right margin to accommodate a figure legend. While designed to be used by nicePlots and bvt plotting
functions, it can also be used indpendantly as in the example below.
legend
, prepCategoryWindow
, niceBox
, niceDots
, niceBar
, niceVio
oMar<-par("mar")
nMar<-oMar
nMar[4]<-5.1
par(mar=nMar)
data(iris)
plot(iris$Sepal.Length,iris$Sepal.Width, col=iris$Species, cex=0, main="Iris Legend Example")
iSpec<-levels(iris$Species)
for(i in seq(length(iSpec))) {
points(iris[iris$Species==iSpec[i],1],iris[iris$Species==iSpec[i],2],
pch=14+i,col=makeColorMatrix()[i,2])
}
par(mar=oMar)
makeNiceLegend(iSpec,col=makeColorMatrix()[1:3,2],shapeScale=15:17,size=1, shape="cs")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.