Learn R Programming

descriptr (version 0.5.2)

ds_cross_table: Two way table

Description

Creates two way tables of categorical variables. The tables created can be visualized as barplots and mosaicplots.

Usage

ds_cross_table(data, var1, var2)

# S3 method for ds_cross_table plot(x, stacked = FALSE, proportional = FALSE, print_plot = TRUE, ...)

ds_twoway_table(data, var1, var2)

Arguments

data

A data.frame or a tibble.

var1

First categorical variable.

var2

Second categorical variable.

x

An object of class cross_table.

stacked

If FALSE, the columns of height are portrayed as stacked bars, and if TRUE the columns are portrayed as juxtaposed bars.

proportional

If TRUE, the height of the bars is proportional.

print_plot

logical; if TRUE, prints the plot else returns a plot object.

...

Further arguments to be passed to or from methods.

Examples

Run this code
# NOT RUN {
k <- ds_cross_table(mtcarz, cyl, gear)
k

# bar plots
plot(k)
plot(k, stacked = TRUE)
plot(k, proportional = TRUE)

# alternate
ds_twoway_table(mtcarz, cyl, gear)

# }

Run the code above in your browser using DataLab