knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(descriptr) library(dplyr)
In this document, we will introduce you to functions for exploring and visualizing categorical data.
We have modified the mtcars
data to create a new data set mtcarz
. The only
difference between the two data sets is related to the variable types.
str(mtcarz)
The ds_cross_table()
function creates two way tables of categorical variables.
ds_cross_table(mtcarz, cyl, gear)
If you want the above result as a tibble, use ds_twoway_table()
.
ds_twoway_table(mtcarz, cyl, gear)
A plot()
method has been defined which will generate:
k <- ds_cross_table(mtcarz, cyl, gear) plot(k)
k <- ds_cross_table(mtcarz, cyl, gear) plot(k, stacked = TRUE)
k <- ds_cross_table(mtcarz, cyl, gear) plot(k, proportional = TRUE)
The ds_freq_table()
function creates frequency tables.
ds_freq_table(mtcarz, cyl)
A plot()
method has been defined which will create a bar plot.
k <- ds_freq_table(mtcarz, cyl) plot(k)
The ds_auto_freq_table()
function creates multiple one way tables by creating a
frequency table for each categorical variable in a data set. You can also
specify a subset of variables if you do not want all the variables in the data
set to be used.
ds_auto_freq_table(mtcarz)
The ds_auto_cross_table()
function creates multiple two way tables by creating a
cross table for each unique pair of categorical variables in a data set. You
can also specify a subset of variables if you do not want all the variables in
the data set to be used.
ds_auto_cross_table(mtcarz, cyl, gear, am)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.