Learn R Programming

tigerstats (version 0.1.6)

barchartGC: Easy barcharts from raw and tabular data

Description

Wrapper for barchart in package lattice. Creates a barchart from raw data, using formula-data syntax similar to that of xtabs. There are very few options.

Usage

barchartGC(x,data=parent.frame(),type="frequency",main=NULL)

Arguments

x
Either a formula or an object that can be coerced to a table. If formula, it must be of the form ~var or ~var1+var2.
data
Usually a data frame that supplies the variables in x. Variables not in the data argument are searched for in the parent environment.
type
Possible values are "frequency" and "percent".
main
An optional title

Value

  • A trellis object describing the barchart.

Examples

Run this code
#barchart of counts for one factor variable:
barchartGC(~sex,data=m111survey)

#barchart with percentages and title:
barchartGC(~sex,data=m111survey,
   type="percent",
   main="Distribution of Sex")

#barchart of counts, to study the relationship between
#two factor variables:
barchartGC(~sex+seat,data=m111survey)

#percentage barchart, two factor variables:
barchartGC(~sex+seat,data=m111survey,type="percent")

#From tabulated data:
sexseat <- xtabs(~sex+seat,data=m111survey)
barchartGC(sexseat,type="percent",main="Sex and Seating Preference")

#from tabulated data:
dieTosses <- c(one=8,two=18,three=11,four=7,five=9,six=7)
barchartGC(dieTosses,main="60 Rolls of a Die")

Run the code above in your browser using DataLab