---
title: "Histograms"
author: "David Gerbing"
output: 
  rmarkdown::html_vignette:
    toc: true
vignette: >
  %\VignetteIndexEntry{histogram}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
---

```{r}
library("lessR")
```


## Histogram

One of the most frequently encountered visualizations for continuous variables is the histogram.

>_Histogram_: Bin similar values into a group, then plot the frequency of occurrence of the data values in each bin as the height of the corresponding bar.

A call to a function to create a histogram has to contain the name of the variable that creates the bins and then tabulates the counts. With the `Histogram()` function, that variable name is the first argument passed to the function, and often, as in this example, the _only_ argument passed to the function. 


First read the Employee data included as part of __lessR__.

```{r read}
d <- Read("Employee")
```

To illustrate, consider the continuous variable _Salary_ in the Employee data table.  Use `Histogram()` to tabulate and display the number of employees in each department, here relying upon the default data frame (table) named _d_.

```{r hs, fig.width=4, fig.height=3.5, fig.align='center', fig.cap="Histogram of tablulated counts for the bins of Salary."}
Histogram(Salary)
```

The `Histogram()` function provides a default color theme. The function also provides the corresponding frequency distribution, summary statistics, the table that lists the count of each category, from which the histogram is constructed, as well as an outlier analysis based on Tukey's rules for box plots.

## Customize the Histogram

The parameters `bin_start`, `bin_width`, and `bin_end` are available to customize the histogram.

```{r binwidth, fig.width=4, fig.height=3.5, fig.align='center', fig.cap="Customized histogram."}
Histogram(Salary, bin_start=35000, bin_width=14000)
```

Easy to change the color, either by changing the color theme with `style()`, or just change the fill color with `fill`. Can refer to standard R colors, as shown with **lessR** function `showColors()`, or implicitly invoke the **lessR** color palette generating function `getColors()`. Each 30 degrees of the color wheel is named, such as `"greens"`, `"rusts"`, etc, and implements a sequential color palette. 

Use the `color` parameter to set the border color, here turned off.

```{r colors, fig.width=4, fig.height=3.5, fig.align='center', fig.cap="Customized histogram."}
Histogram(Salary, fill="reds", color="transparent")
```


## Density Plot

The histogram portrays a continuous distribution with discrete bins.

>_Density plot_: A smooth curve that estimates the underlying continuous distribution.  

To invoke, add the `density` parameter. The result is the filled density curve superimposed on the histogram.


```{r density, fig.width=4, fig.height=3.5, fig.align='center', fig.cap="Histogram with density plot."}
Histogram(Salary, density=TRUE)
```


## VBS Plot

A more modern version of the density plot combines the violin plot, box plot, and scatter plot into a single visualization, called here the VBS plot.

```{r VBS, fig.width=4, fig.height=3.5, fig.align='center', fig.cap="VBS plot."}
Plot(Salary)
```



## Full Manual

Use the base R `help()` function to view the full manual for `Histogram()`. Simply enter a question mark followed by the name of the function.

```
?Histogram
```

