Learn R Programming

plotrix (version 2.5-2)

barhier: Display a set of hierarchically associated variables

Description

Display a data frame in which the values in each successive column represent subcategories of the previous column as a block of stacked rectangles.

Usage

barhier(x,left=0,top,right=1,showval=TRUE,showcount=TRUE,firstcall=TRUE,
  col=NA,fade=FALSE,...)

Arguments

x
A data frame in which each successive column represents subcategories of the previous column.
left
The left edge of the current stack of rectangles in user units.
top
The top of the current stack of rectangles in user units.
right
The right edge of the current stack of rectangles in user units.
showval
Whether to display the values representing the categories.
showcount
Whether to display the count for the categories.
firstcall
A flag for the function - do not alter this.
col
Optional fill colors for the rectangles.
fade
Whether to incrementally decrease the saturation of the bar colors at each level.
...
additional arguments passed to plot.

Value

  • nil

Details

barhier displays hierarchical categories as stacked rectangles. It accepts a data frame in which the values in the first column represent categories, the values in the second column represent subcategories of the first column, and so on. The first column will be displayed as a stack of rectangles, the height of each proportional to the count for each category. Each substack of rectangles in the second stack will represent the breakdown of counts for its superordinate category and so on through the columns. Empty categories are ignored and NAs will produce gaps. Typically, the user will simply pass the data frame, which should only contain columns that are hierarchical categories, set showval and showcount to the desired values, and pass colors for the top level categories if these are wanted. If colors are passed, it is best to have at least as many colors as there are categories in the first column or some will be recycled. Currently, these colors will be "faded out" in successive stacks of rectangles toward white. The firstcall argument is necessary for the function to initialize the plot, as each breakdown involves a recursive call. If it is changed, the best that can be expected is an uninformative plot.

See Also

plot,smoothColors

Examples

Run this code
cat1<-sample(LETTERS[1:4],40,TRUE)
 cat2<-paste(cat1,sample(1:4,40,TRUE),sep="")
 cat3<-paste(cat2,sample(letters[1:4],40,TRUE),sep="")
 hcats<-data.frame(cat1,cat2,cat3)
 barhier(hcats,col=c("#ff8080","#dddd80","#80ff80","#8080ff"),
  main="Hierarchical count chart",fade=TRUE)

Run the code above in your browser using DataLab