Draw a Dot Chart

DESCRIPTION:

Plots a dot chart from a vector. A grouping variable, and group summary may be used along with other options.

USAGE:

dotchart(data, labels=<<see below>>, groups=NULL, gdata=NULL, horiz=T,  
          pch="o", lty=2) 

REQUIRED ARGUMENTS:

data
vector of all data values. Missing values (NA) are allowed.

OPTIONAL ARGUMENTS:

labels
vector of labels for the data values. If this is missing, labels are taken from the names of data.
groups
categorical variable used for splitting the data vector into groups and providing group labels.
gdata
vector of group data, that is, an overall value for each group. This could be a sum or an average, for example.
horiz
logical flag: should data values be on horizontal or vertical axis?
pch
character to be used as the plot character.
lty
line type used in drawing the dotted line.

Graphical parameters may also be supplied as arguments to this function (see par ). In addition, the high-level graphics arguments described under plot.default and the arguments to title may be supplied to this function.

SIDE EFFECTS:

a chart is plotted with all elements of groups together, and the elements identified with labels, if present.

DETAILS:

Missing values and Infs are not plotted.

SEE ALSO:

barplot , boxplot , par , title .

EXAMPLES:

# a simple function to make dotcharts from matrices with dimnames 
dotchart.mat <- function(mat, col.is.main = T, ...) 
{ 
        if(col.is.main) 
                mat <- t(mat) 
        g.lab <- dimnames(mat)[[2]] 
        if(length(g.lab)) 
                g <- factor(col(mat), labels = g.lab) 
        else g <- factor(col(mat)) 
        la.lab <- dimnames(mat)[[1]] 
        if(length(la.lab)) 
                la <- factor(row(mat), labels = la.lab) 
        else la <- factor(row(mat)) 
        dotchart(mat, labels = la, groups = g, ...) 
        invisible() 
} 
perc.data <- c(5.4, 3.1, 3.5, 5.7, 8.6, 25.0, 20.4, 
        26.0, 22.0, 36.3, 34.1, 28.0, 14.4, 11.4, 4.5) 
percent <- matrix(perc.data,ncol=3, byrow=T) 
community <- c("Old Suburb", "Coast County", "New Suburb") 
service <- c("Child Care", "Health Services", 
      "Community Centers", "Family & Youth", "Other") 
com <- factor(col(percent), label=community) 
serv <- factor(row(percent), label=service) 
dotchart(percent, labels=com, group=serv) 
dotchart(percent, labels=serv, group=com, horiz=F) 
# now plot the same thing with the median percent for each service 
gmed <- tapply(percent, com, median) 
dotchart(percent, labels=serv, group=com, gdata=gmed)