2  Some datasets πŸ“Ž

In this documentation, we will use a few datasets from RDatasets and from the Plotly datasets.

(ns tableplot-book.datasets
  (:require [tablecloth.api :as tc]
            [clojure.string :as str]
            [scicloj.kindly.v4.kind :as kind]))

A convenience function for fetching a dataset and taking care of its column names:

(defn fetch-dataset [dataset-name]
  (-> dataset-name
      (->> (format "https://vincentarelbundock.github.io/Rdatasets/csv/%s.csv"))
      (tc/dataset {:key-fn (fn [k]
                             (-> k
                                 str/lower-case
                                 (str/replace #"\." "-")
                                 keyword))})
      (tc/set-dataset-name dataset-name)))

2.1 Edgar Anderson’s Iris Data

(defonce iris
  (fetch-dataset "datasets/iris"))
iris

datasets/iris [150 6]:

:rownames :sepal-length :sepal-width :petal-length :petal-width :species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
6 5.4 3.9 1.7 0.4 setosa
7 4.6 3.4 1.4 0.3 setosa
8 5.0 3.4 1.5 0.2 setosa
9 4.4 2.9 1.4 0.2 setosa
10 4.9 3.1 1.5 0.1 setosa
… … … … … …
140 6.9 3.1 5.4 2.1 virginica
141 6.7 3.1 5.6 2.4 virginica
142 6.9 3.1 5.1 2.3 virginica
143 5.8 2.7 5.1 1.9 virginica
144 6.8 3.2 5.9 2.3 virginica
145 6.7 3.3 5.7 2.5 virginica
146 6.7 3.0 5.2 2.3 virginica
147 6.3 2.5 5.0 1.9 virginica
148 6.5 3.0 5.2 2.0 virginica
149 6.2 3.4 5.4 2.3 virginica
150 5.9 3.0 5.1 1.8 virginica

2.2 Motor Trend Car Road Tests

(defonce mtcars
  (fetch-dataset "datasets/mtcars"))
mtcars

datasets/mtcars [32 12]:

:rownames :mpg :cyl :disp :hp :drat :wt :qsec :vs :am :gear :carb
Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4
Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2
Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
… … … … … … … … … … … …
Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2
AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2
Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4
Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2
Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1
Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2
Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2
Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4
Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8
Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2

2.3 US economic time series

(defonce economics-long
  (fetch-dataset "ggplot2/economics_long"))
economics-long

ggplot2/economics_long [2870 5]:

:rownames :date :variable :value :value01
1 1967-07-01 pce 506.7 0.00000000
2 1967-08-01 pce 509.8 0.00026525
3 1967-09-01 pce 515.6 0.00076152
4 1967-10-01 pce 512.2 0.00047060
5 1967-11-01 pce 517.4 0.00091554
6 1967-12-01 pce 525.1 0.00157439
7 1968-01-01 pce 530.9 0.00207066
8 1968-02-01 pce 533.6 0.00230168
9 1968-03-01 pce 544.3 0.00321722
10 1968-04-01 pce 544.0 0.00319155
… … … … …
2860 2014-06-01 unemploy 9460.0 0.53485435
2861 2014-07-01 unemploy 9608.0 0.54653825
2862 2014-08-01 unemploy 9599.0 0.54582774
2863 2014-09-01 unemploy 9262.0 0.51922318
2864 2014-10-01 unemploy 8990.0 0.49775006
2865 2014-11-01 unemploy 9090.0 0.50564459
2866 2014-12-01 unemploy 8717.0 0.47619799
2867 2015-01-01 unemploy 8903.0 0.49088182
2868 2015-02-01 unemploy 8610.0 0.46775085
2869 2015-03-01 unemploy 8504.0 0.45938265
2870 2015-04-01 unemploy 8526.0 0.46111944

2.4 Tips dataset

(defonce tips
  (-> "https://raw.githubusercontent.com/plotly/datasets/master/tips.csv"
      (tc/dataset {:key-fn keyword})))
tips

https://raw.githubusercontent.com/plotly/datasets/master/tips.csv [244 7]:

:total_bill :tip :sex :smoker :day :time :size
16.99 1.01 Female No Sun Dinner 2
10.34 1.66 Male No Sun Dinner 3
21.01 3.50 Male No Sun Dinner 3
23.68 3.31 Male No Sun Dinner 2
24.59 3.61 Female No Sun Dinner 4
25.29 4.71 Male No Sun Dinner 4
8.77 2.00 Male No Sun Dinner 2
26.88 3.12 Male No Sun Dinner 4
15.04 1.96 Male No Sun Dinner 2
14.78 3.23 Male No Sun Dinner 2
… … … … … … …
10.77 1.47 Male No Sat Dinner 2
15.53 3.00 Male Yes Sat Dinner 2
10.07 1.25 Male No Sat Dinner 2
12.60 1.00 Male Yes Sat Dinner 2
32.83 1.17 Male Yes Sat Dinner 2
35.83 4.67 Female No Sat Dinner 3
29.03 5.92 Male No Sat Dinner 3
27.18 2.00 Female Yes Sat Dinner 2
22.67 2.00 Male Yes Sat Dinner 2
17.82 1.75 Male No Sat Dinner 2
18.78 3.00 Female No Thur Dinner 2
source: notebooks/tableplot_book/datasets.clj