Learn R Programming

inlmisc (version 0.5.5)

AddPoints: Add Points to Plot

Description

Add point symbols to a plot. Proportional circle symbols may be used to represent point data, where symbol area varies in proportion to an attribute variable.

Usage

AddPoints(
  x,
  y = NULL,
  z = NULL,
  zcol = 1,
  crs = NULL,
  xlim = NULL,
  ylim = NULL,
  zlim = NULL,
  inches = c(0, 0.2),
  scaling = c("perceptual", "mathematical", "radius"),
  bg = "#1F1F1FCB",
  bg.neg = NULL,
  fg = NA,
  lwd = 0.7,
  cex = 0.7,
  format = NULL,
  legend.loc = "topright",
  inset = 0.02,
  bty = c("o", "n"),
  breaks = NULL,
  break.labels = NULL,
  quantile.breaks = FALSE,
  make.intervals = FALSE,
  title = NULL,
  subtitle = NULL,
  draw.legend = TRUE,
  draw.points = FALSE,
  add = TRUE,
  ...
)

Arguments

x, y

'numeric' vector or 'SpatialPoints*'. x and y coordinates for the centers of the circle symbols. If numeric, can be specified in any way which is accepted by xy.coords.

z

'numeric' vector, 'integer' vector, or 'factor'. Attribute variable. For objects of class factor, a fixed radius is used for circle symbols, see inches argument description.

zcol

'integer' count or 'character' string. Attribute name or column number to extract from if x is of class 'SpatialGridDataFrame'.

crs

'character' string or 'CRS'. Coordinate reference system arguments

xlim

'numeric' vector of length 2. x limits for the plot.

ylim

'numeric' vector of length 2. y limits for the plot.

zlim

'numeric' vector of length 2. z limits for the plot.

inches

'numeric' vector of length 2. Radii limits for the drawn circle symbol. Alternatively, a single number can be given resulting in a fixed radius being used for all circle symbols; this overrides proportional circles and the function behaves like the points function.

scaling

'character' string. Selects the scaling algorithm to use for symbol mapping. Specify "perceptual" or "mathematical" for proportional scaling (Tanimura and others, 2006), or "radius" for scaling symbol size to radius (usually a bad idea).

bg

'character' vector or 'function'. Fill color(s) for circle symbols. A color palette also may be specified.

bg.neg

'character' vector or 'function'. Fill color(s) for circle symbols corresponding to negative z values. A color palette also may be specified. For circle symbols corresponding to positive z values, the bg argument is used for color(s).

fg

'character' string. Outer-line color for circle symbols. Specify a value of NA to remove the symbols outer line, and NULL to match the outer-line color with the symbols fill color.

lwd

'numeric' number. Line width for drawing circle symbols.

cex

'numeric' number. Character expansion factor for legend labels.

format

'character' string. Formatting for legend values, see formatC for options.

legend.loc

'character' string. Position of the legend in the main plot region; see GetInsetLocation function for keyword descriptions.

inset

'numeric' number. Inset distance of the legend from the margins as a fraction of the main plot region. Defaults to 2 percent of the axis range.

bty

'character' string. Type of box to be drawn about the legend. A value of "o" (the default) results in a box and a value of "n" suppresses the box.

breaks

'numeric' vector. Finite breakpoints for the legend circle symbols.

break.labels

'character' vector. Break labels with length equal to breaks.

quantile.breaks

'logical' flag. If true, breaks are set to the sample quantiles of z.

make.intervals

'logical' flag. If true, represent z within intervals. See findInterval function for details. Unused if quantile.breaks is true.

title

'character' string. Main title to be placed at the top of the legend.

subtitle

'character' string. Legend subtitle to be placed below the main title.

draw.legend

'logical' flag. If true, a legend is drawn.

draw.points

'logical' flag. If true, the circle symbols are drawn.

add

'logical' flag. If true, circle symbols (and an optional legend) are added to an existing plot.

...

Graphics parameters to be passed to PlotMap. Unused if add = TRUE.

Value

Invisible NULL

References

Tanimura, S., Kuroiwa, C., and Mizota, T., 2006, Proportional Symbol Mapping in R: Journal of Statistical Software, v. 15, no. 5, 7 p.

Examples

Run this code
# NOT RUN {
set.seed(2)
n <- 50L
x <- cbind(runif(n, 1, 10), runif(n, 1, 500))
z <- runif(n, 0, 1000)
z[sample.int(n, 2)] <- 0
AddPoints(x, z = z, fg = "#00000080", lwd = 0.5, title = "Title",
          subtitle = "Subtitle", add = FALSE)

idxs <- sample.int(n, floor(n / 2))
z[idxs] <- -z[idxs]
AddPoints(x, z = z, bg.neg = "#2A8FBDCB",
          breaks = pretty(z, n = 8),
          legend.loc = "bottomleft", add = FALSE)

Pal1 <- colorRampPalette(c("#CA0020CB", "#F4A582CB"), alpha = TRUE)
Pal2 <- colorRampPalette(c("#0571B0CB", "#92C5DECB"), alpha = TRUE)
AddPoints(x, z = z, bg = Pal1, bg.neg = Pal2, add = FALSE)

AddPoints(x, z = z, bg = Pal1, bg.neg = Pal2, add = FALSE,
          make.intervals = TRUE)

AddPoints(x, z = z, bg = Pal1, bg.neg = Pal2, add = FALSE,
          make.intervals = TRUE, inches = 0.1)

AddPoints(x, z = abs(z), title = "Quantiles", bg = topo.colors,
          quantile.breaks = TRUE, add = FALSE)

z <- as.factor(rep(c("dog", "cat", "ant", "pig", "bat"),
                   length.out = n))
bg <- GetColors(nlevels(z), scheme = "bright", alpha = 0.8)
AddPoints(x, z = z, bg = bg, add = FALSE)

AddPoints(x, draw.legend = FALSE, add = FALSE)

# }

Run the code above in your browser using DataLab