Database Reference
In-Depth Information
4.
We sort that by the cap shape:
(sort-by :cap-shape)
5.
Then we convert it to a new dataset:
i/to-dataset)
We implicitly pass the output of that expression to the
incanter.charts/bar-chart
using
incanter.core/with-data
, and we have our chart.
Creating histograms with Incanter
Histograms are useful when we want to see the distribution of data. They are even effective
with continuous data. In a histogram, the data is divided into a limited number of buckets,
commonly 10, and the number of items in each bucket is counted. Histograms are especially
useful for inding how much data are available for various percentiles. For instance, these
charts can clearly show how much of your data was in the 90th percentile or lower.
Getting ready
We'll use the same dependencies in our
project.clj
ile as we did in
Creating scatter plots
with Incanter
.
We'll use this set of imports in our script or REPL:
(require '[incanter.core :as i]
'[incanter.charts :as c]
'incanter.datasets)
For this recipe, we'll use the iris dataset that we used in
Creating scatter plots in Incanter
:
(def iris (incanter.datasets/get-dataset :iris))
How to do it...
As we did in the previous recipes, we just create the graph and display it with
incanter.
core/view
:
1.
We create a histogram of the iris' petal length:
(def iris-petal-length-hist
(c/histogram (i/sel iris :cols :Petal.Length)
:title "Iris Petal Lengths"
:x-label "cm"
:nbins 20))