Learn R Programming

RCPA3 (version 1.3.1)

freqC: Reports the frequency distribution of dataset variable with table and bar chart

Description

Generates frequency distribution table and bar chart to describe distribution of variable values. Based on freq function in descr package.

Usage

freqC(x, w, data, digits = 2, rowlabs, printC = FALSE, plot = TRUE, main,
  xlab, ylab, bar.col, ...)

Value

A frequency distribution table.

Arguments

x

The variable to be analyzed. If dataset not specified with data argument, should be a vector in form dataset$var.

w

(Optional) Sample weights (must be numeric if used), If dataset not specified with data argument, should be in form dataset$weighvar

data

(Optional) Name of dataset that contains x (and w) variable.

digits

(Optional) Number of digits to display after decimal point (default=2).

rowlabs

(Optional) Vector specifying custom text for labeling table rows and chart bars. The rowlabs vector must correspond to x variable's levels (if the variable has five levels, rowlabs must be length 5). Useful when default value labels are too long.

printC

(Optional) Do you want to print frequency distribution table and bar chart (if plot is used) to .html file in working directory? (default: FALSE)

plot

(Optional) Do you want a bar chart? (default set to TRUE)

main

(Optional) Main title of bar chart.

xlab

(Optional) The x-axis label of bar chart.

ylab

(Optional) The y-axis label of bar chart.

bar.col

(Optional) The name of color to use for bars. Default is "gray80".

...

(Optional) Additional arguments passed to descr::freq function.

Textbook References

  • Philip H. Pollock and Barry C. Edwards, An R Companion to Political Analysis, 3rd Edition (Thousand Oaks, CA: Sage Publications, Forthcoming 2022), Chapter 2.

  • Philip H. Pollock and Barry C. Edwards, The Essentials of Political Analysis, 6th Edition (Thousand Oaks, CA: Sage Publications, 2020), pp. 39-55. ISBN-13: 978-1506379616; ISBN-10: 150637961.

Online Resources

Examples

Run this code
   library(RCPA3)
   
   # unordered factors
   freqC(x=region, data=world)
   
   # ordered factors
   freqC(x=threat.from.china, data=nes)

Run the code above in your browser using DataLab