12 Change Over Time
Line charts and their variants β showing change over a sequence.
(ns napkinsketch-book.change-over-time
(:require
;; Tablecloth β dataset manipulation
[tablecloth.api :as tc]
;; Kindly β notebook rendering protocol
[scicloj.kindly.v4.kind :as kind]
;; Napkinsketch β composable plotting
[scicloj.napkinsketch.api :as sk]))Line
Connected line through data points.
(def wave {:x (range 30)
:y (map #(Math/sin (* % 0.3)) (range 30))})(-> wave
(sk/lay-line :x :y))Grouped Lines
Color separates multiple series.
(def waves {:x (concat (range 30) (range 30))
:y (concat (map #(Math/sin (* % 0.3)) (range 30))
(map #(Math/cos (* % 0.3)) (range 30)))
:fn (concat (repeat 30 :sin) (repeat 30 :cos))})(-> waves
(sk/lay-line :x :y {:color :fn}))Thick Line
Constant stroke width via :size.
(-> wave
(sk/lay-line :x :y {:size 4}))Line with Points
Overlay points on a grouped line plot.
(def growth
{:day [1 2 3 4 5 1 2 3 4 5]
:value [10 15 13 18 22 8 12 11 16 19]
:group [:a :a :a :a :a :b :b :b :b :b]})(-> growth
(sk/view :day :value {:color :group})
sk/lay-line
sk/lay-point)Step
Horizontal-then-vertical connected points.
(-> {:x [1 2 3 4 5]
:y [2 4 1 5 3]}
(sk/lay-step :x :y)
sk/lay-point)Step by Group
Grouped step lines.
(-> growth
(sk/view :day :value {:color :group})
sk/lay-step
sk/lay-point)Area
Filled area under a line.
(-> {:x (range 30)
:y (map #(Math/sin (* % 0.3)) (range 30))}
(sk/lay-area :x :y))Stacked Area
Each group fills above the previous.
(-> {:x (concat (range 10) (range 10) (range 10))
:y (concat [1 2 3 4 5 4 3 2 1 0]
[2 2 2 3 3 3 2 2 2 2]
[1 1 1 1 2 2 2 1 1 1])
:group (concat (repeat 10 "A") (repeat 10 "B") (repeat 10 "C"))}
(sk/lay-stacked-area :x :y {:color :group}))Whatβs Next
- Relationships β heatmaps, contours, and 2D density
- Polar β radial charts for cyclical data