@@ -76,24 +76,6 @@ sgplot(
7676
7777![ iris] ( assets/iris_violin.svg )
7878
79-
80- ** Bar chart**
81-
82- ``` julia
83- bar_ds = Dataset (x = repeat (1 : 50 , outer= 50 ), group = repeat (1 : 50 , inner = 50 ))
84- insertcols! (bar_ds, :y => rand (nrow (bar_ds)))
85- sgplot (
86- bar_ds,
87- Bar (x= 2 , response= 3 , group= 1 ), # refer columns by their indices
88- groupcolormodel = Dict (:scheme => " turbo" ),
89- xaxis= Axis (show= false ),
90- yaxis= Axis (show= false ),
91- legend = false
92- )
93- ```
94-
95- ![ bar_random] ( assets/bar_random.svg )
96-
9779** unemployment stacked area plot across industries**
9880
9981Reproducing an example from the [ ` vega ` ] ( https://vega.github.io ) `s examples collection.
@@ -116,108 +98,6 @@ sgplot(
11698
11799![ unemployment] ( assets/unemployment.svg )
118100
119- ** [ Revenue by Music Format, 1973–2018] ( https://observablehq.com/@mbostock/revenue-by-music-format-1973-2018 ) **
120-
121- Reproducing an example from the [ ` D3 ` ] ( http://d3js.org ) `s examples collection.
122-
123- ``` julia
124- music = filereader (" assets/music.csv" )
125- color_ds = filereader (" assets/color_ds.csv" )
126- leftjoin! (music, color_ds, on = :Format )# sort data - original example
127- sort! (music, [:Year , :order ], rev = [false , true ]) # rev = true for :order to make the color similar to the original example
128-
129- inbillion (x) = x/ 10 ^ 9 # make the yaxis' values in billion $
130- setformat! (music, r" Infla" => inbillion)
131-
132- sgplot (
133- music,
134- [
135- Bar (x = :Year , response = r" Infla" ,
136- group = :Format ,
137- grouporder = :data ,
138- outlinethickness = 0 ,
139- space = 0.05 ,
140- legend = :music_leg
141- )
142- ],
143- groupcolormodel = reverse! (color_ds[:, :Color ]),
144- yaxis = Axis (title = " Revenue (billion, adj.)" , domain = false , titlepos= [5 ,5 ], titleangle= 0 , titlealign= :left , titlesize= 10 ),
145- xaxis = Axis (values = 1975 : 5 : 2015 ),
146- legend = Legend (name = :music_leg , rowspace= 0 , gridalign = :all , columns = 4 , orient = :top , values = color_ds[:, :Format ]),
147- width = 700
148- )
149- ```
150-
151- ![ music] ( assets/music.svg )
152-
153- ** Normalised bar chart**
154-
155- ``` julia
156- sgplot (
157- music,
158- Bar (x= :Year , response= r" Infla" ,
159- group= :Format ,
160- grouporder= :data ,
161- outlinethickness= 0 ,
162- space= 0.05 ,
163- normalize= true ,
164- legend= :music_leg
165- ),
166- groupcolormodel= reverse! (color_ds[:, :Color ]),
167- yaxis= Axis (title= " Revenue %" , domain= false , nice= false , d3format = " %" ),
168- xaxis= Axis (values= 1975 : 5 : 2015 ),
169- legend= Legend (name= :music_leg , rowspace= 0 , gridalign= :all , columns= 4 , orient= :top , values= color_ds[:, :Format ]),
170- width= 700
171- )
172- ```
173-
174- ![ normalised_music] ( assets/normalised_music.svg )
175-
176- ** [ Stacked Bar Chart, Diverging] ( https://observablehq.com/@d3/diverging-stacked-bar-chart ) **
177-
178- Reproducing an example from the [ ` D3 ` ] ( http://d3js.org ) `s examples collection.
179-
180- Using the ` baselineresponse ` keyword argument to control the baseline of bars in each category.
181-
182- ``` julia
183- ds = filereader (" assets/politifact.csv" )
184- ds_order = Dataset (ruling = [" true" , " mostly-true" , " half-true" ," barely-true" , " false" , " full-flop" , " pants-fire" ],
185- Ruling = [" True" , " Mostly true" , " Half true" , " Mostly false" , " False" , " False" , " Pants on fire!" ],
186- order = 1 : 7 ,
187- weight = [0 ,0 ,0 ,- 1 ,- 1 ,- 1 ,- 1 ])
188- leftjoin! (ds, ds_order, on = :ruling )
189- sort! (ds, [:order ], rev= true ) # order Ruling
190- modify! (
191- groupby (ds, :speaker ),
192- :count => x-> x ./ IMD. sum (x), # normalise counts
193- [:count , :weight ]=> byrow (prod) => :baseline
194- )
195-
196- sgplot (
197- ds,
198- [
199- Bar (y= :speaker , response= :count ,
200- group= :Ruling ,
201- grouporder= :data ,
202- baselineresponse= :baseline ,
203- orderresponse= :baseline ,
204- outlinethickness= 0.1 ,
205- legend = :bar_leg ,
206- x2axis= true
207- ),
208- RefLine (values = 0.0 , axis= :x2axis )
209- ],
210- x2axis= Axis (title = " ← more lies · Truthiness · more truths →" , domain = false , d3format= " %" , nice= false , grid= true ),
211- yaxis= Axis (title = " " , domain = false , ticks = false ),
212- legend = Legend (name = :bar_leg , title = " " , orient= :top , columns= 0 , size= 200 , columnspace = 10 ),
213- width= 800 ,
214- height= 200 ,
215- groupcolormodel= [" #d53e4f" , " #fc8d59" , " #fee08b" , " #e6f598" , " #99d594" , " #3288bd" ]
216- )
217- ```
218-
219- ![ stack-div-bar] ( assets/stack-div-bar.svg )
220-
221101# Examples - grouped datasets
222102
223103** Cars example**
0 commit comments