Open jimka2001 opened 1 month ago
If I change the data structure to the following, no points get plotted.
{:data {:values polished-data}
:title {:text chart-title}
:description chart-title
:axes [{:orient "bottom"
;; TODO this is NOT setting the label
:title x-label}
{:orient "left"
;; TODO this is NOT setting the label
:title y-label}]
:encoding {:x {:field x-label ;; !!! CHANGED TO x-label
:type "quantitative"}
:y {:field y-label ;; !!! CHANGED TO y-label
:type "quantitative"}
:color {:field "series"
:type "nominal"}}
:mark "line"}
If I change the {:data {:values polished-data} ...}
value as follows, it get the correct x and y axis labels. I really doubt that is the intended way. I'm creating a keyword with a call to keyword
whose text is the text I'd like on the label, then creating polished-data
using those keywords.
(defn series-format-plot-data
"encode plotting data into an hashmap ready to pass to oz/view!"
[chart-title x-label y-label data]
;; data is of form [[string [(x y) (x y) (x y) ...]]
;; [string [(x y) (x y) (x y) ...]]
;; ...]
(let [x-key (keyword x-label)
y-key (keyword y-label)
polished-data (for [[label aseq] data
[x y] aseq]
{x-key (float x)
y-key (float y)
:series label})]
{:data {:values polished-data}
:title {:text chart-title}
:description chart-title
:axes [{:orient "bottom"
;; TODO this is NOT setting the label
:title x-label}
{:orient "left"
;; TODO this is NOT setting the label
:title y-label}]
:encoding {:x {:field x-label ;; "x" ;; x-label
:type "quantitative"}
:y {:field y-label ;; "y" ;; y-label
:type "quantitative"}
:color {:field "series"
:type "nominal"}}
:mark "line"}))
I asked this elsewhere but with no answer, so please allow me to ask it here.
I have a clojure function,
series-format-plot-data
, defined here https://github.com/jimka2001/clojurein-student/blob/ce1e21511a04d17f851a294f39fcf7b457f4427e/clojurein-source-code/src/lecture/vega_plot.clj#L8 which creates a plot usingoz
. I can't figure out how to set the label on the x and y axes. Can someone help?When I call the function,![Baby Names 44427929273960329145](https://github.com/metasoarous/oz/assets/6414129/2ba9dd8a-f4a1-4bdf-b4aa-62de4e5c566b)
sample-plot-2
, defined here https://github.com/jimka2001/clojurein-student/blob/ce1e21511a04d17f851a294f39fcf7b457f4427e/clojurein-source-code/src/lecture/baby_name_plot.clj#L98 I get a graphs looking like the following which has x and y axis labels as "x" and "y" rather than "Year" and "Percentage" as requested.I'm basically returning a data structure such as the following: