powered by
cross_table creates two way tables of categorical variables. The tables created can be visualized as barplots and mosaicplots.
cross_table
cross_table(var1, var2)# S3 method for cross_table plot(x, beside = FALSE, proportional = FALSE, ...)# S3 method for cross_table mosaicplot(x, ...)
# S3 method for cross_table plot(x, beside = FALSE, proportional = FALSE, ...)
# S3 method for cross_table mosaicplot(x, ...)
First categorical variable
Second categorical variable
An object of class cross_table
a logical value. If FALSE, the columns of height are portrayed as stacked bars, and if TRUE the columns are portrayed as juxtaposed bars.
a logical value. If TRUE, the height of the bars is proportional
further arguments to be passed to or from methods.
cross_table returns an object of class "cross_table". An object of class "cross_table" is a list containing at least the following components:
"cross_table"
obs number of observations
levels of the second categorical variable
levels of the first categorical variable
names of the variables
table of the variables
table of percentages
table of row percentages
table of column percentages
total of columns
total of columns as a percentage
k <- cross_table(mtcars$cyl, mtcars$am) # bar plots plot(k) plot(k, beside = TRUE) plot(k, proportional = TRUE) # mosaic plots mosaicplot(k)
Run the code above in your browser using DataLab