#### Overview of this book

Clojure for Data Science
Credits
Acknowledgments
www.PacktPub.com
Preface
Free Chapter
Statistics
Inference
Correlation
Network Analysis
Time Series
Visualization
Index

## Histograms

A histogram is one way to visualize the distribution of a single sequence of values. Histograms simply take a continuous distribution, bin it, and plot the frequencies of points falling into each bin as a bar. The height of each bar in the histogram represents how many points in the data are contained in that bin.

We've already seen how to bin data ourselves, but `incanter.charts` contains a `histogram` function that will bin the data and visualize it as a histogram in two steps. We require `incanter.charts` as `c` in this chapter (and throughout the book).

```(defn ex-1-12 []
(i/\$ "Electorate")
(c/histogram)
(i/view)))```

The preceding code generates the following chart:

We can configure the number of bins data is segmented into by passing the keyword argument `:nbins` as the second parameter to the histogram function:

```(defn ex-1-13 []
(-> (uk-electorate)
(c/histogram :nbins 200)
(i/view)))```

The preceding graph shows a single, high peak but expresses the shape of the data quite crudely. The following graph shows fine detail, but the volume of the bars obscures the shape of the distribution, particularly in the tails:

Choosing the number of bins to represent your data is a fine balance—too few bins and the shape of the data will only be crudely represented, too many and noisy features may obscure the underlying structure.

```(defn ex-1-14 []
The following shows a histogram of `20` bars instead:
This final chart containing `20` bins seems to be the best representation for this data so far.