Book Image

Clojure Data Analysis Cookbook

By : Eric Rochester
Book Image

Clojure Data Analysis Cookbook

By: Eric Rochester

Overview of this book

<p>Data is everywhere and it's increasingly important to be able to gain insights that we can act on. Using Clojure for data analysis and collection, this book will show you how to gain fresh insights and perspectives from your data with an essential collection of practical, structured recipes.<br /><br />"The Clojure Data Analysis Cookbook" presents recipes for every stage of the data analysis process. Whether scraping data off a web page, performing data mining, or creating graphs for the web, this book has something for the task at hand.<br /><br />You'll learn how to acquire data, clean it up, and transform it into useful graphs which can then be analyzed and published to the Internet. Coverage includes advanced topics like processing data concurrently, applying powerful statistical techniques like Bayesian modelling, and even data mining algorithms such as K-means clustering, neural networks, and association rules.</p>
Table of Contents (18 chapters)
Clojure Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating bar charts with Incanter


Another common type of chart is a bar chart. These are good for comparing the sums or the counts of a few categories in the data.

Getting ready

We'll use the same dependencies in our project.clj file as we did in the Creating scatter plots with Incanter recipe.

We'll use the following 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 a standard dataset of chick weights. This comes with Incanter, so it's simple to load.

(def chick-weight (incanter.datasets/get-dataset :chick-weight))

How to do it…

In this example, we'll chart the weight of the chicks by their diets.

  1. We get the total weights for the chicks eating each diet with the incanter.core/$rollup function.

    (def chick-weight-bar
      (i/with-data
        (i/$order :Diet :asc
          (i/$rollup :sum :weight :Diet chick-weight))
        (c/bar-chart (i/$map int :Diet)
                     :weight
                     :title...