Simple Bar chart
using InMemoryDatasets, StatisticalGraphics, DLMReader
Bar
produces bar chart, by default it assigns the frequency of each value to the height of the corresponding bar
movies = filereader(joinpath(dirname(pathof(StatisticalGraphics)),
"..", "docs", "assets", "movies.csv"),
dlmstr="::")
sgplot(movies, Bar(x="Major Genre"))
To produce horizontal bar chart, pass the analysis variable to y
sgplot(movies, Bar(y="Major Genre"))
A response
column can be pass to Bar
when the analysis variable is different from categories. By default the sum of the response
column will be used as the height of each bar. User can pass any function in the form of (f, x)->...
to stat
to customise the aggregation of response
##IMD.maximum handles missing values
sgplot(movies, Bar(y="Major Genre", response="Worldwide Gross", stat=IMD.maximum))
User can control the order of bars by passing orderresponse
. Bar
automatically aggregate the values of orderresponse
in each category and arrange the category in the final output accordingly.
sgplot(movies, Bar(y="Major Genre", response="Worldwide Gross",
stat=IMD.maximum, orderresponse="Worldwide Gross",
orderstat=IMD.maximum))
Similar to other marks there are many keyword arguments to fine tune the final output
sgplot(movies, Bar(y="Major Genre", response="Worldwide Gross",
stat=IMD.maximum, orderresponse="Worldwide Gross",
orderstat=IMD.maximum, colorresponse="Worldwide Gross",
colorstat=mean,
colormodel=Dict(:scheme=>:blues)))
And
sgplot(movies, Bar(y="Major Genre", response="Worldwide Gross",
stat=IMD.maximum, orderresponse="Worldwide Gross",
orderstat=IMD.maximum, colorresponse="Worldwide Gross",
colorstat=mean,
colormodel=Dict(:scheme=>:browns),
barcorner=[0,5,0,5],
space=0.4,
outlinecolor=:black,
legend=:bar_leg,
missingmode=1
),
xaxis=Axis(title="Maximum Worldwide Gross",
domain=false, d3format="\$,f", grid=true),
yaxis=Axis(domain=false, grid=true),
legend=Legend(name=:bar_leg, d3format="\$,f",
title="Average Worldwide Gross", orient=:bottom,
direction=:horizontal, gradientlength=600),
clip=false)
This page was generated using DemoCards.jl and Literate.jl.