Skip to content

Commit

Permalink
Merge pull request #21 from srenatus/nitpicks-data-science-notebook
Browse files Browse the repository at this point in the history
Nitpicks data science notebook
  • Loading branch information
jackrusher authored Sep 30, 2024
2 parents de6e6c5 + e666ec3 commit f4f450e
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions notebooks/data_science.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
[meta-csv.core :as csv]
[next.jdbc :as jdbc]
[next.jdbc.result-set :as rs]
[next.jdbc.sql :as sql]
[nextjournal.clerk :as clerk]))

;; # Exploring the world in data
Expand Down Expand Up @@ -58,12 +57,12 @@
{:data {:values life-expectancy}
:width 700
:height 500
:mark {:type "point"
:tooltip {:field "Country"}}
:mark {:type :point}
:encoding {:x {:field :gdp
:type :quantitative}
:y {:field :life-expectancy
:type :quantitative}}})
:type :quantitative}
:tooltip {:field :country}}})

;; Unsurprisingly, it seems that living in an extremely poor country
;; has negative consequences for life expectancy. On the other hand,
Expand Down Expand Up @@ -122,29 +121,29 @@
{:data {:values expectancy-and-gini}
:width 600
:height 1600
:mark {:type "point"
:tooltip {:field :country}}
:mark {:type :point}
:encoding {:x {:field :gini
:type :quantitative}
:y {:field :country
:type :nominal
:sort "x"}}})
:sort :x}
:tooltip {:field :country}}})

;; And now to have a look at whether inequality and life expectancy
;; are correlated:
(clerk/vl
{:data {:values expectancy-and-gini}
:mark "rect"
:mark :rect
:width 700
:height 500
:encoding {:x {:bin {:maxbins 25}
:field :life-expectancy
:type "quantitative"}
:type :quantitative}
:y {:bin {:maxbins 25}
:field :gini
:type "quantitative"}
:color {:aggregate "count" :type "quantitative"}}
:config {:view {:stroke "transparent"}}})
:type :quantitative}
:color {:aggregate :count :type :quantitative}}
:config {:view {:stroke :transparent}}})

;; It seems like the mass of long lived countries are also in the
;; lower two thirds of the inequality distribution. A little filtering
Expand Down Expand Up @@ -201,14 +200,14 @@
{:data {:values world-happiness+regression}
:width 700
:height 500
:layer [{:mark {:type "point"
:tooltip {:field :country}}
:layer [{:mark {:type :point}
:encoding {:x {:field :score
:type :quantitative
:scale {:zero false}}
:y {:field :gdp
:type :quantitative}}}
{:mark {:type "line" :color "#ccc"}
:type :quantitative}
:tooltip {:field :country}}}
{:mark {:type :line :color "#ccc"}
:encoding {:x {:field :score
:type :quantitative
:scale {:zero false}}
Expand Down Expand Up @@ -241,14 +240,14 @@
(take 20))}
:width 700
:height 500
:mark {:type "point"
:tooltip {:field :country}}
:mark {:type :point}
:encoding {:x {:field :score
:type :quantitative
:scale {:zero false}}
:y {:field :gini
:type :quantitative
:scale {:zero false}}}})
:scale {:zero false}}
:tooltip {:field :country}}})

;; This does, at least at first glance, support the notion that the
;; happiest people — just like the longest lived ones — tend to
Expand Down

0 comments on commit f4f450e

Please sign in to comment.