Instantly share code, notes, and snippets.

Embed
What would you like to do?
(def passengers {:$schema "https//vega.github.io/schema/vega/v4.json",
:width 750
:height 500
:padding 25
:data {:name "passenger-count"}
:scales [{:name "xscale"
:type "band"
:domain {:data "passenger-count" :field "hour"}
:range "width"}
{:name "yscale"
:domain {:data "passenger-count" :field "sum_passenger"}
:nice true
:range "height"}]
:axes [{:orient "left"
:scale "yscale"
:titlePadding 25
:title "Number of passengers"
:titleFontSize 16
:labelFontSize 14}
{:orient "bottom"
:scale "xscale"
:labelOverlap "parity"
:title "Hour"
:titlePadding 35
:titleFontSize 16
:labelFontSize 14}]
:marks {
:type "rect",
:from {:data "passenger-count"}
:encode {
:enter {
:x {:scale "xscale" :field "hour"}
:width {:scale "xscale" :band 1}
:y {:scale "yscale" :field "sum_passenger"}
:y2 {:scale "yscale" :value 0}}
:update {:tooltip {:signal "{\"Hour\":datum['category']}"}
:x {:scale "xscale" :field "hour"}
:width {:scale "xscale" :band true :offset -1}
:y {:scale "yscale" :field "sum_passenger"}
:y2 {:scale "yscale", :value 0},
:fill {:value "steelblue"}
:fillOpacity {:value 1.0}}
:exit {:fill {:value "grey"}
:fillOpacity {:value 0.1}}}}})
(def distance {:$schema "https//vega.github.io/schema/vega/v4.json",
:width 500
:height 400
:padding 25
:data {:name "distance-distribution"}
:scales [{:name "xscale"
:type "band"
:domain {:data "distance-distribution" :field "distance"}
:range "width"}
{:name "yscale"
:domain {:data "distance-distribution" :field "count"}
:nice true
:range "height"}]
:axes [{:orient "left"
:scale "yscale"
:titlePadding 25
:title "# of passages"
:titleFontSize 16
:labelFontSize 14}
{:orient "bottom"
:scale "xscale"
:labelOverlap "parity"
:title "Distance [miles]"
:titlePadding 35
:titleFontSize 16
:labelFontSize 14}]
:marks {
:type "rect",
:from {:data "distance-distribution"}
:encode {
:enter {
:x {:scale "xscale" :field "distance"}
:width {:scale "xscale" :band 1}
:y {:scale "yscale" :field "count"}
:y2 {:scale "yscale" :value 0}}
:update {:tooltip {:signal "{\"Hour\":datum['distance']}"}
:x {:scale "xscale" :field "category"}
:width {:scale "xscale" :band true :offset -1}
:y {:scale "yscale" :field "count"}
:y2 {:scale "yscale", :value 0},
:fill {:value "steelblue"}
:fillOpacity {:value 1.0}}
:exit {:fill {:value "grey"}
:fillOpacity {:value 0.1}}}}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment