Sunday, August 22, 2010

Drawing a dotchart for dataframe in R

It has been suggested that bar charts and dot plots are excellent for displaying grouped data.
The dotchart function in R has the following syntax(typing ?dotchart inside an R session):



Cleveland's Dot Plots

Description:

Draw a Cleveland dot plot.

Usage:

dotchart(x, labels = NULL, groups = NULL, gdata = NULL,
cex = par("cex"), pch = 21, gpch = 21, bg = par("bg"),
color = par("fg"), gcolor = par("fg"), lcolor = "gray",
xlim = range(x[is.finite(x)]),
main = NULL, xlab = NULL, ylab = NULL, ...)

Arguments:

x: either a vector or matrix of numeric values (‘NA’s are
allowed). If ‘x’ is a matrix the overall plot consists of
juxtaposed dotplots for each row.

labels: a vector of labels for each point. For vectors the default
is to use ‘names(x)’ and for matrices the row labels
‘dimnames(x)[[1]]’.

..... More! please read the rest from an actual R session.


If R is a dataframe with column names (header) and row names, then the dot chart will use these
labels to group the data. Each column of data constitute a group and for each group, a series of
dot charts are displayed for all the rows belonging to the group.

Surprisingly, R does not display a dataframe natively inspite of the builtin VADeaths dataset working. Copying the VADeaths dataset to a file and reading it as a dataframe, (replacing embedded spaces with an underscore), resulted in R giving an error message that it expects a matrix or vector(roughly, a one column matrix). So we typecast it as a matrix and we are able to use the dotchart function.

Here is the menu page of our dotchart generator:


and a sample output.



We hasten to add that our page for a dot chart generator is only for quick visualization of data.

No comments:

Post a Comment