Learn R Programming

DescTools (version 0.99.57)

BubbleLegend: Add a Legend to a Bubble Plot

Description

Add a legend for bubbles to a bubble plot.

Usage

BubbleLegend(x, y = NULL, area, cols, labels = NULL, cols.lbl = "black",
             width = NULL, xjust = 0, yjust = 1, inset = 0, border = "black",
             frame = TRUE, adj = c(0.5, 0.5), cex = 1, cex.names = 1,
             bg = NULL, ...)

Arguments

x

the left x-coordinate to be used to position the legend. See 'Details'.

y

the top y-coordinate to be used to position the legend. See 'Details'.

area

the area(s) for the bubbles in bubble legend.

cols

the color appearing in the legend.

labels

a vector of labels to be placed at the right side of the legend.

cols.lbl

the textcolor for the labels of the bubbles.

width

the width of the legend.

xjust

how the legend is to be justified relative to the legend x location. A value of 0 means left justified, 0.5 means centered and 1 means right justified.

yjust

the same as xjust for the legend y location.

inset

inset distance(s) from the margins as a fraction of the plot region when legend is placed by keyword.

border

defines the bordor color of each rectangle. Default is none (NA).

frame

defines the bordor color of the frame around the whole legend. Default is none (NA).

adj

text alignment, horizontal and vertical.

cex

extension factor for the area, default 1.0.

cex.names

character extension for the labels, default 1.0.

bg

the background color for the bubble legend.

...

further arguments are passed to the function text.

Author

Andri Signorell <andri@signorell.net>

Details

The labels are placed in the middle of the legend.

The location of the legend may be specified by setting x to a single keyword from the list "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" and "center". This places the legend on the inside of the plot frame at the given location. Partial argument matching is used. The optional inset argument specifies how far the legend is inset from the plot margins. If a single value is given, it is used for both margins; if two values are given, the first is used for x- distance, the second for y-distance. This is the same behaviour as it's implemented in legend.

See Also

legend, FindColor, legend

Examples

Run this code
PlotBubble(x=d.pizza$delivery_min, y=d.pizza$temperature, area=d.pizza$price,
           xlab="delivery time", ylab="temperature",
           col=SetAlpha(as.numeric(d.pizza$area)+2, .5), border="darkgrey",
           na.rm=TRUE, main="Price-Bubbles", panel.first=grid())

BubbleLegend("bottomleft", area=c(1500, 1000, 500), frame=TRUE,
             cols=SetAlpha("steelblue",0.5), bg="green",
             labels=c(1500, 1000, 500), cex=0.8,
             cols.lbl=c("yellow", "red","blue"))

Run the code above in your browser using DataLab