Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions src/clojure_norway/meetup_2025_12.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
^{:kindly/hide-code true
:clay {:title "# Noway Clojure Meetup Dec. 2025: Data analysis"
:clay {:title "A featherweight introduction to datasets and plots for the Norwegian Clojurians"
:quarto {:author [:com.github/teodorlu :daslu]
:description "Meetup notes"
:category :clojure
Expand All @@ -12,28 +12,63 @@
[scicloj.kindly.v4.kind :as kind]
[scicloj.metamorph.ml.rdatasets :as rdatasets]
[scicloj.tableplot.v1.plotly :as plotly]
[tablecloth.api :as tc]))
[tablecloth.api :as tc]
[tech.v3.dataset :as ds]))

;; - Has GDP per capita improved since 1950?
;; - Are trends different per continent?
;; This document serves as a featherweight introduction to Tablecloth datasets
;; and Tableplot plotting for programmers familiar with Clojure, but unfamiliar
;; with Data Science.

;; We will pick a real problem for our learning endevaours:
;;
;; > Has GDP per capita improved since 1950?
;;
;; This is a big question, and we will only provide the beginning of an answer.

(def ds
(-> (rdatasets/gapminder-gapminder)
(tc/order-by :year)))

;; Our source data is the [gapminder dataset](https://www.gapminder.org/data/).
;; Luckily for us, the gapminder dataset is available as clean Clojure data!
;;
;; Let's have a peek:

(ds/head ds)
(count (ds/rows ds))

;; We observe,
;; - each country+year is it's own row
;; - there are lots of rows

;; To see better, let's plot each country along its own line.

(-> ds
(tc/order-by :year)
(plotly/layer-line {:=x :year
:=y :gdp-percap
:=color :country}))

;; We expected GDP per capita to *increase*.
;; But there's a sharply decreasing line!
;; Hovering our cursor over the line, we see that it's Kuwait.
;;
;; Let's investigate.
;; First, let's narrow our focus to only Kuwait.

(def kuwait? (comp #{"Kuwait"} :country))

(def ds-kuwait
(-> ds
(tc/order-by [:country :year])
(tc/select-rows kuwait?)))

;; First, we repeat GDP per capita per year, only for Kuwait.

(-> ds-kuwait
(plotly/layer-line {:=x :year
:=y :gdp-percap
}))

;; Why does gdp per capita decrease in Kuwait?

(-> ds-kuwait
Expand Down