knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The fdistr package provides an efficient way to create frequency distribution tables and use those tables to generate Pareto charts.
Frequency distribution tables show the frequency of various outcomes in a data set. Each entry in the table contains a frequency or count of values within a particular group or interval, and in this way, the table summarizes the distribution of values in the data set.
A Pareto chart visually depicts the frequency distribution table.
You can install the released version of fdistr from CRAN with:
install.packages("fdistr")
And the development version from GitHub with:
# install.packages("devtools") devtools::install_github("dtminnick/fdistr")
This basic example which shows you how to use the fdistr package with the
built-in words
dataset.
Start by loading the words
dataset. The dataset contains a data frame with
six variables about a collection of words taken from the first paragraph of
James Joyce's short story "The Dead."
library(fdistr) data(words) str(words)
It is possible to create a frequency distribution table with any of the six
variables in this table. For this example, pass the first_letter
variable
to the create_table
function and return the table (stored as a data frame)
to a variable called table
. Use the dec_pos
argument to set the number
of positions following the decimal to be displayed in the table.
table <- create_table(words$first_letter, dec_pos = 3) table
In this example, the frequency distribution table provides a row for each unique first letter in the dataset, arranged in descending order of count, with the frequency, cumulative count and cumulative frequency for each first letter.
To plot the data in a Pareto chart, pass the table
data frame to the
create_pareto
function along with character strings for the plot labels.
create_pareto(table, title = "Pareto Chart", subtitle = "Frequency of first letters in Joyce's 'The Dead'", x_label = "Letter", y_label = "Frequency", caption = "Chart generated using the built-in words data.")
Bars in the chart show the frequency of each first letter and a line shows the cumulative frequency with points to highlight the cumulative frequency for each value above the bars. The Pareto chart is an effective way to show the frequencies of values.
When working with a continuous variable, such as 'letter_count' in the words
dataset,
the create_ecdf
function creates an empirical cumulative distribution function,
or ECDF, plot. The ECDF plot shows the proportion of observations that are less
than or equal to each observed value.
create_ecdf(words$letter_count, title = "ECDF Chart", subtitle = "ECDF of letter counts in Joyce's 'The Dead'", x_label = "Letter Count", y_label = "Frequency", caption = "Chart generated using the built-in words data.")
The height of each step in the plot is the frequency of each value in the observed data and the length of each horizontal line shows the distance between values. Dashed vertical lines plot the quartiles along with their values on the x-axis.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.