Skip to content

Commit e1cb382

Browse files
committed
composable_plotting wip
1 parent 0892169 commit e1cb382

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

src/data_visualization/aog/composable_plotting.clj

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,18 @@ mpg
17351735
:x-domain (numeric-extent (clean x))
17361736
:y-domain (numeric-extent (clean y))}))))
17371737

1738+
;; ### 🧪 What `:loess` Returns
1739+
;;
1740+
;; Sampled points along the fitted curve, one set per color group:
1741+
1742+
(-> (view iris [[:sepal-length :petal-length]])
1743+
(lay (loess {:color :species}))
1744+
first
1745+
resolve-view
1746+
compute-stat
1747+
(update :points (fn [pts] (mapv #(-> % (update :xs count) (update :ys count)) pts)))
1748+
kind/pprint)
1749+
17381750
;; ### 🧪 Scatter + Regression
17391751
;;
17401752
;; `lay` applies two layers to the same data -- one scatter, one regression line:
@@ -2292,10 +2304,11 @@ mpg
22922304
;; The [tips](https://rdrr.io/cran/reshape2/man/tips.html) dataset records
22932305
;; restaurant bills with tip amount, party size, day, and smoker status.
22942306

2295-
(let [tips (tc/dataset "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv")]
2296-
(-> (view tips [["total_bill" "tip"]])
2297-
(lay (point {:color "day"}))
2298-
(facet-grid "smoker" "sex")
2307+
(let [tips (tc/dataset "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv"
2308+
{:key-fn keyword})]
2309+
(-> (view tips [[:total_bill :tip]])
2310+
(lay (point {:color :day}))
2311+
(facet-grid :smoker :sex)
22992312
(plot {:width 600 :height 500})))
23002313

23012314
;; ### 🧪 Faceted Scatter with Free Y-Scale
@@ -2537,7 +2550,7 @@ mpg
25372550

25382551
;; ### ⚙️ Annotation Constructors
25392552

2540-
(defn text-label
2553+
(defn text
25412554
"Text labels at data positions. `col` is the column used for label text."
25422555
([col] {:mark :text :stat :identity :text-col col})
25432556
([col opts] (merge {:mark :text :stat :identity :text-col col} opts)))
@@ -2627,7 +2640,7 @@ mpg
26272640
(-> (view iris [[:sepal-length :sepal-width]])
26282641
(lay (point {:color :species}))
26292642
(concat (-> (view means [[:sepal-length :sepal-width]])
2630-
(lay (text-label :species))))
2643+
(lay (text :species))))
26312644
plot))
26322645

26332646
;; ---
@@ -2876,6 +2889,13 @@ mpg
28762889
;; All visual constants -- colors, margins, radii -- live in one `defaults`
28772890
;; map that can be overridden per-plot via `:config`.
28782891
;;
2892+
;; **Axis labels from column names.**
2893+
;; Standalone and faceted plots auto-infer axis titles from column names
2894+
;; via `fmt-name` (e.g. `:sepal-length` → "sepal length"). SPLOM grids
2895+
;; skip this since they already show column headers. The `scale`
2896+
;; constructor and `plot` options both accept overrides, and custom
2897+
;; domains work via `(scale :x {:domain [4 8]})`.
2898+
;;
28792899
;; ### 📖 Composition, reviewed
28802900
;;
28812901
;; The compositional core of this notebook is small: `view` and `cross`
@@ -2941,12 +2961,6 @@ mpg
29412961
;; into smaller steps -- a preparation phase, a rendering phase, and an
29422962
;; assembly phase -- would make it easier to understand and modify.
29432963
;;
2944-
;; **Axis labels are auto-inferred** from column names and shown on
2945-
;; standalone and faceted plots (but not SPLOM grids, which use column
2946-
;; headers). Override with `(plot views {:x-label "..." :title "..."})`
2947-
;; or `(scale :x {:label "..."})`. Custom domains also work:
2948-
;; `(scale :x {:domain [4 8]})`.
2949-
;;
29502964
;; **Partial validation.**
29512965
;; `view` checks that the specified columns actually exist in the
29522966
;; dataset, which catches typos early. But marks, stats, and `plot` options
@@ -2987,9 +3001,6 @@ mpg
29873001
;; backends? SVG is universal and works well with Clay, but Canvas or
29883002
;; WebGL would be needed for large datasets.
29893003
;;
2990-
;; - **Axis labels and titles:** How should they be specified? As part of the
2991-
;; view map, as plot options, or inferred from column metadata?
2992-
;;
29933004
;; - **Faceting:** Is faceting part of the data algebra (another way to split
29943005
;; views) or a separate layout concern? Right now it sits between the two --
29953006
;; `facet` modifies views, but the grid layout is handled by `plot`.

0 commit comments

Comments
 (0)