stackedBarplot: Produces a hanging barplot

stackedBarplotR Documentation

Produces a hanging barplot

Description

This produces a series of stacked bar plots staggered so that the baseline corresponds to a particular state level. This is primarily designed for producing plots of probability vectors coming out of Bayes net scoring.

Usage

stackedBarplot(height, width = 1, space = 0.2, offset = 0, names.arg = NULL,
               legend.text = NULL, horiz = FALSE, density = NULL,
               angle = 45, col = NULL, border = par("fg"),
               main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
               xlim = NULL, ylim = NULL, xpd = TRUE, axis = TRUE,
               axisnames = TRUE, cex.axis = par("cex.axis"),
               cex.names = par("cex.axis"), newplot = TRUE,
               axis.lty = 0, ...)

Arguments

height

A matrix giving the heights of the bars. The columns represent bars, and the rows represent groups within each bar.

width

A numeric vector of length equal to the number of columns in height giving the width of the bars. If value is shorter than number of columns in height it is recycled to produce the correct length.

space

A numeric vector of length equal to the number of columns in height giving the space between the bars. If value is shorter than number of columns in height it is recycled to produce the correct length.

offset

A numeric vector of length equal to the number of columns in height giving distance by which the bars should be offset from the zero line on the axis. Setting this to a non-zero value produces a hanging barplot.

names.arg

If not missing, used as axis labels (see axis).

legend.text

If node null, a legend is generated (see legend).

horiz

A logical value. If true, stacked bars are printed horizontally instead of vertically.

density

Density of shading lines (see rect). This should be a scalar or a vector of length equal to the number of rows of height.

angle

Angle of shading lines (see rect). This should be a scalar or a vector of length equal to the number of rows of height.

col

Color used for each bar. This should be a scalar or a vector of length equal to the number of rows of height. If not supplied a grayscale gradient is built.

border

Color for the rectangle borders (see rect). This should be a scalar or a vector of length equal to the number of rows of height.

main

Main title for plot (see title).

sub

Subtitle for plot (see title).

xlab

X-axis label for plot (see title).

ylab

Y-axis label for plot (see title).

xlim

Limits in user co-ordinates for the x-axis. Should be a vector of length 2.

ylim

Limits in user co-ordinates for the y-axis. Should be a vector of length 2.

xpd

A logical value controlling clipping. (see par).

axis

A logical value. If true, a numeric scale is printed on the appropriate axis.

axisnames

A logical value. If true, column names are printed on the appropriate axis.

cex.axis

Character size used for the numeric axis labels (see axis).

cex.names

Character size used for the text (column names) axis labels (see axis).

newplot

A logical value. If true a new graphics region is created. If false, the plot is placed on top of the existing graphics region.

axis.lty

A value passed as the lty argument to axis when plotting the text (column name) axis.

...

Other graphics parameters passed to rect, axis and title.

Details

This is a more detailed version of the stackedBars graph which allows finer control. It is used mainly by compareBars.

There are some differences from stackedBars. First, height can be any value, not just a vector of probability. Second, offset is given as a numeric value in the units of height, rather than as an index into the array of heights. Most of the rest of the arguments merely expose the graphical arguments to the user.

Value

The midpoints of the bars are returned invisibly.

Author(s)

Russell Almond

See Also

compareBars, colorspread, buildMarginTab, marginTab, barplot,stackedBars

Examples

margins <- data.frame (
 Trouble=c(Novice=.19,Semester1=.24,Semester2=.28,Semseter3=.20,Semester4=.09),
 NDK=c(Novice=.01,Semester1=.09,Semester2=.35,Semseter3=.41,Semester4=.14),
 Model=c(Novice=.19,Semester1=.28,Semester2=.31,Semseter3=.18,Semester4=.04)
)
margins <- as.matrix(margins)
baseline <- apply(margins[1:2,],2,sum)

stackedBarplot(margins,offset=-baseline,
            main="Marginal Distributions for NetPASS skills",
            sub="Baseline at 2nd Semester level.",
            col=hsv(223/360,.2,0.10*(5:1)+.5))


ralmond/CPTtools documentation built on Dec. 27, 2024, 7:15 a.m.