Learn R Programming

dr (version 2.0.4)

markby: Produce a vector of colors/symbols to mark points

Description

This function creates marking of points by color or symbol for use in graphs.

Usage

markby(z, use="color", values=NULL, color.fn=rainbow, na.action="na.use")

Arguments

z
a variable with a few distict values that will define the groups for marking.
use
if equal to "color", will returna list of colors. If anything else, it will return a list of symbols for marking.
values
a list with as many values as unique values of z that determine the colors or symbols. If this is not set, then the function rainbow is used for colors and 1:length(unique(z)) is used for symbols.
na.action
By default, missing values (NAs) are treated as another category in the color marking. Setting this argument to anything else will return NA for the missing category names. This will cause an error in R graphics routines, but see below for usage of t

Value

  • Returns length(z) values that specify the color or symbol for each point.

References

This function is to help users familiar with Arc, as discussed in R. D. Cook and S. Weisberg (1999). Applied Regression Including Computing and Graphics, New York: Wiley.

Examples

Run this code
x <- rnorm(100)
  y <- rnorm(100)
  z <- cut(rnorm(100),3)
# Scatterplot, mark using color with groups determined by Status
  plot(x,y,col=markby(z))
# Scatterplot, mark using symbols with groups determined by Status
  plot(x,y,pch=markby(z,use="symbols"))
# handing of missing values:
  z[1:10] <- NA   # set to missing
  marks <- markby(z,na.action="omit")
  sel <- !is.na(marks)
  plot(x[sel],y[sel],col=marks[sel])

Run the code above in your browser using DataLab