tags. ðDataScience ðDSL
Vegaåã³Vega-Liteã«ã€ããŠ.
Vega: ããŒã¿å¯èŠåèšè¿°ãã©ãŒããã
JSON圢åŒã§ããŒã¿ãèšè¿°ããŠå€æãšã³ãžã³ã«é£ããããšããŒã¿ããããã§ãã. ã°ã©ãã倿ããŠè¡šç€ºãããããšãåæãšããŠ, ããŒã¿æ§é ãšããŠå®£èšçã«å®çŸ©ããããšãã§ãã. ããšãã°, matplotlibã®ãããªå°çšã®ã©ã€ãã©ãªã«äŸåããªã.
ð§Vega-Lite
軜éãã€é«åºŠãªVegaã©ãããŒ.
Python Bindingsã«ðAltairããã. Clojureã¯, ðClojure: Ozãåç §.
Infos
- links.
- https://vega.github.io/vega-lite/
- https://github.com/vega/vega-lite
- https://www.youtube.com/watch?v=9uaHRWj04D4
- éçºããã²ãšãã¡ã®ç޹ä»ãã¬ãŒã³.
Basic Concepts
æžãæ¹ãããããªããšãã¯examplesãåç §. Online Editorããã¢ã¯ã»ã¹ã§ããExampleã®ã»ãããããŠãããµã³ãã«ã®æ°ãå€ã(ææ°?).
https://vega.github.io/vega-lite/examples/
View Specicication
Vega-Liteã®ä»æ§ã§å®çŸ©ãããJSONãView Specification(Spec)ãšãã.
doc: https://vega.github.io/vega-lite/docs/
åºæ¬ãšãªã圢ã以äž.
- spec
- title
- width/height
- data
- mark
- encoding
Data
ããŒã¿ãœãŒã¹ã®å®çŸ©.
ããŒã¿ã®åãæž¡ãæ¹æ³ã«ã¯æå®ããããã©ãŒããããããã®ã§æ³šæ. ãããã®é å(vector of maps)ãæž¡ãå¿ èŠããã. ããŒã¿æ¬äœã«ã¯valuesãšããkeyãå¿ èŠ.
ãããã®é åã§ã¯ãªã, é åããã®ãŸãŸæž¡ãã«ã¯datasetãšããå¥ã®æå®æ¹æ³ããã.
https://vega.github.io/vega-lite/docs/data.html
Transform
ããŒã¿æŽåœ¢.
Mark
ã°ã©ãã®çš®é¡.
Encoding
x軞/y軞èšå®(axis).
Vega-lite: ã€ã³ã¿ã©ã¯ãã£ã
ã€ã³ã¿ã©ã¯ãã£ããªæäœã¯Vega liteã®ç®çæ©èœã®ã²ãšã€.
Example Gallery - Interactive | Vega-Lite
ãã®ãµã€ãã®èª¬æããšãŠããããããã(å³ã).
Tooltips | Data Visualisation in Data Science
Tooltip
ããŠã¹ããããŒãããšæ å ±ãåºãæ©èœã¯Tooltipãšãã. ç°¡åãªæå¹åã¯, :markã®ãªãã·ã§ã³ã§ {:tooltip true}ãšããããš.
(def line-plot
{:data {:values data}
:encoding {:x {:field "timestamp"
:type "temporal"
:timeUnit "monthdatehoursminutes"
:title "timestamp"}
:y {:field "close" :type "quantitative"}}
:mark {:type "line" :tooltip true}})
Zooming and Panning
ããŠã¹ãã€ãŒã«ã§æ¡å€§çž®å°.
{:params [{:name âgridâ :select âintervalâ :bind âscalesâ}]}ã远å .
(def line-plot
{:data {:values data}
:params [{:name "grid" :select "interval" :bind "scales"}]
:encoding {:x {:field "timestamp" :type "temporal"}
:y {:field "close" :type "quantitative"}}
:mark {:type "line"}})
Brush
ç¯å²ãæå®ããŠãŽãã§ãŽãã§.
vega-lite: ã°ã©ãå¥
ãã¹ãã°ã©ã
ðãã¹ãã°ã©ã ã®vega-liteã§ã®è¡šç€º.
vega-liteã§aggregateãããå Žåãšèªåã§é »åºŠãèšç®ããå Žå(bined data)ã®2ã€ããã.
- https://vega.github.io/vega-lite/examples/histogram.html
- https://vega.github.io/vega-lite/examples/bar_binned_data.html
vaga-liteã§aggregateããå Žåã¯, {:aggreage âcountâ}ãæž¡ãããšã§åºçŸé »åºŠããšã«count, :bin {:binned true :step 500}ãæž¡ããš, stepããšã«ãŸãšããŠè¡šç€º.
(def histgram
{:data {:values (map (fn [x] {:spread x}) spreads)}
:encoding {:x {:field "spread"
:bin {:binned true :step 500}
:axis {:offset 10}}
:y {:aggregate "count"}}
:width 500
:mark {:type "bar"}})
ããŒãœã¯è¶³ãã£ãŒã
(def candlestick
{:width 500
:data {:values data}
:encoding {:x {:field "timestamp"
:type "temporal"
:title "Date/Time"
:axis {:format "%m/%d"
:labelAngle -45
:title "Date/Time"}}
:y {:type "quantitative"
:scale {:zero false}
:axis {:title "Price"}}
:color {:condition {:value "#06982d" ;; grean color
:test "datum.open < datum.close"}
:value "#ae1325" ;; red color
}}
:layer [{:mark "rule"
:encoding {:y {:field "low"} :y2 {:field "high"}}}
{:mark "bar"
:encoding {:y {:field "open"} :y2 {:field "close"}}}]})
- https://vega.github.io/vega-lite/examples/layer_candlestick.html
- Kibana ã§ããŒãœã¯è¶³ãã£ãŒããåºããŠã¿ã - Qiita
éåŒãVega-lite
åºåãµã€ãºã調æŽããã«ã¯?
height/widthãæå®ãã.
æ±ãç¯å²ãæå®ããŠè¡šç€ºããã«ã¯?
ããšãã°, 2500000ã¿ãããªå€§ããªå€ã®åšèŸºã®æ°ãplotãããšãã«, 0ããã®è¡šç€ºã§ã¯ãªã2000000ã«ããã«ã¯?
:scaleãšãã屿§ã®:domainãæå®ãã.
(def bar-plot
{:data {:values bars}
:encoding {:x {:field "timestamp"
:type "temporal"
:timeUnit "datehoursminutes"}
:y {:field "close" :type "quantitative"
:scale {:domain [2000000 2500000]}}}
:mark {:type "line"}})
X軞/Y軞ã«marginããããã«ã¯?
{:encoding {:x {:axis {:offset 10}}}}
环ç©å(Cumulative Sum)ã衚瀺ããã«ã¯?
transformã«windowãªãã·ã§ã³(op=sum)ãæå®ãã.
(def cum-spec
{:mark {:type "line"}
:data {:values vl-values}
:transform [{:window [{:op "sum"
:field "rebate"
:as "cum"}]}]
:encoding {:x {:field "datetime" :type "temporal"}
:y {:field "cum" :type "quantitative"}}})
èªåã§èšç®ããããããã£ãšæ¥œã§ãã, ããããæ©èœãæåããŒã«ãšããŠçµã¿èŸŒãŸããŠãããšãããvegaã®åŒ·åãªå©ç¹ãªããšã¯åŒ·èª¿ããã. èšãæããã°ããŒã¿ãšã©ã ãæœè±¡ã宣èšçã«å®çŸ©ãããšã°ã©ããæåããã.
Other Tips
æ°ã¥ããããš.
æå»ã¯ããŒã«ã«ã¿ã€ã ã§æ±ããšãã
ãŸãŒã³ã¿ã€ã ã¯ãã®ãŸãŸã§ã¯vegaã§ã¯äœ¿ããªãã®ã§æååã«ãããlocal timeã«å€æããå¿ èŠããã. ããŒã¿åŠçãèãããšlocal timeãstringããããã¿ãŒ.
ðAltair
Vegaã®Python Wrapperã§ãã, Pythonã§ã€ã³ã¿ã©ã¯ãã£ããªã°ã©ãã衚瀺ã§ãã. Plotyã®å¯ŸæéЬ.
å£ã³ããã€ãŒã.
- https://twitter.com/Nagi7692/status/1301175266580938753
- https://twitter.com/saruo_hunbook/status/1499764724216385538
References
è¬ã®åªè¯ãªèª¬æè³æ.
ð®Next in Data Visualization - MIT
MITã«ããæ¬¡äžä»£ããŒã¿èŠèŠåã«ã€ã³ã¿ã©ã¯ãã£ãæ§ãå¿ èŠãªçç±ã®ãã¬ãŒã³. å°ã倢ãæãã.
Next in Data Visualization | Arvind Satyanarayan || Radcliffe Institute - YouTube
- Vega-liteã®å®£èšæ§ãåªããŠãã.
- ã€ã³ã¿ã©ã¯ãã£ãæ§ã¯ããŒã¿ãšãã¡ã€ã³ã®å®éšã·ã£ãŒã¬ãšãªã.