legendQuad | R Documentation |
This function adds a legend to an existing plot. The legend is typically a square with each corner assigned a different color. The closer an object in the main plot is to one of four "assignments" (e.g., populations), the more the corresponding color is shown, with assignments of intermediate value displaying as a mixture of colors. The function first draws a "containing" box then a square "color swatch" with a color gradient inside. A legend title and labels for the four corners can be added.
legendQuad(
x,
y = NULL,
inset = 0,
width = 0.2,
height = 0.2,
labels = LETTERS[1:4],
labelAdj = 1,
cols = c("white", "cyan", "black", "red"),
n = 25,
border = par("fg"),
title = "",
titleAdj = c(0.5, 0.9),
aspect = FALSE,
swatchAdjX = c(0.15, 0.85),
swatchAdjY = c(0.25, 0.85),
boxBg = par("bg"),
boxBorder = par("fg"),
...
)
x |
Numeric or character. Describes the location of the legend. This is a numeric value (in which case |
y |
Numeric or |
inset |
Numeric. If |
width |
Numeric. Scaling factor for box width. |
height |
Numeric. Scaling factor for box height. |
labels |
Character vector used to name the four corners of the color swatch in this order: bottom left, top left, top right, bottom right. Leave as |
labelAdj |
Numeric, usually between 0 and 1. Position of corner labels relative to the corners of the swatch. |
cols |
Character list. Names of four colors to be used to create a gradient to fill the color swatch. The first color will be assigned to the lower left corner, the second to the upper left, third to upper right, and fourth to lower right. Note that not every color combination produces a map with a unique color at each coordinate of the color swatch. |
n |
Positive integer, number of squares used to approximate a smooth color map in the swatch. This is the number of cells along each side of the swatch. Higher values create less "blocky" swatches but increase drawing time. |
border |
Character or integer. Name (or integer code) of color to use to draw border of the color swatch. Leave as |
title |
Character or |
titleAdj |
Two numeric values between 0 and 1. Position of the legend relative to the container box. The first pertains to horizontal positioning and the second vertical positioning. |
aspect |
Logical, if |
swatchAdjX |
Two numeric values between 0 and 1. Size of the color swatch in the x-dimension as a proportion of the container box size. The first pertains to the left side of the bar and the second the right side. |
swatchAdjY |
Two numeric values between 0 and 1. Size of the swatch in the y-dimension as a proportion of the container box size. The first pertains to the top of the bar and the second the bottom. Alternatively, if |
boxBg |
Character or integer. Name (or integer code) of color to use to use for box containing legend. Leave as |
boxBorder |
Character or integer. Name (or integer code) of color to use to use for box border containing legend. Leave as |
... |
Arguments to pass to |
Nothing (side effect is to add a legend to an existing graphics device).
legend
, legendGrad
,
data(religion)
head(religion)
religion$others <- rowSums(religion[ , c('unaffiliated', 'hindu', 'folk', 'other', 'jewish')])
religs <- c('christian', 'muslim', 'buddhist', 'others')
par(mfrow=c(1, 2))
plotQuad(religion[ , religs], 'points', background=FALSE, main='Religion by Country')
legendQuad('top', inset=0.01, labels=colnames(relig))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.