Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

bi.bars

Draw pairs of bargraphs based on two groups


Description

When showing e.g., age or education distributions for two groups, it is convenient to plot them back to back. bi.bars will do so.

Usage

bi.bars(x,var=NULL,grp=NULL,horiz,color,label=NULL,zero=FALSE,xlab,ylab,...)

Arguments

x

The data frame or matrix from which we specify the data

var

The variable to plot

grp

a grouping variable.

horiz

horizontal (default) or vertical bars

color

colors for the two groups – defaults to blue and red

label

If specified, labels for the dependent axis

zero

If TRUE, subtract the minimum value to make the numbers range from 0 to max -min. This is useful if showing heights

xlab

xaxis label if appropriate

ylab

y axis label otherwise

...

Further parameters to pass to the graphing program

Details

A trivial, if useful, function to draw back to back histograms/barplots. One for each group.

Value

a graphic

Author(s)

William Revelle

See Also

describe, describeBy and statsBy for descriptive statistics and error.bars error.bars.by and densityBy violinBy for graphic displays

Examples

#data(bfi)
bi.bars(psychTools::bfi,"age","gender" ,ylab="Age",main="Age by males and females")
 bi.bars(psychTools::bfi,"education","gender",xlab="Education",
     main="Education by gender",horiz=FALSE)

psych

Procedures for Psychological, Psychometric, and Personality Research

v2.1.3
GPL (>= 2)
Authors
William Revelle [aut, cre] (<https://orcid.org/0000-0003-4880-9610>)
Initial release
2021-03-21

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.