Skip to content

Instantly share code, notes, and snippets.

@AnupJoseph
Created October 30, 2022 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnupJoseph/e88148585adbef30f7ab992e8caa768b to your computer and use it in GitHub Desktop.
Save AnupJoseph/e88148585adbef30f7ab992e8caa768b to your computer and use it in GitHub Desktop.
Gadfly.with_theme(:dark) do
age_counts = countmap(dataset[!,2])
custom_order = ["18-21","22-24","25-29","30-34", "35-39","40-44","45-49","50-54" ,"55-59","60-69" , "70+"]
age_order = OrderedDict()
# Using the above custom order to make a custom dictionary
for item in custom_order
age_order[item] = age_counts[item]
end
# Trick to calculate percentage of individual elemant
age_percents = values(age_order).*100/nrow(dataset)
barplot =plot(
x=1:length(keys(age_order)),
y=age_percents,
style(bar_spacing=2mm),
Scale.x_discrete(labels=k->custom_order[k]),
Guide.xlabel("Ages of survey respondents"),
Guide.ylabel("% distribution of the survey respondents"),
Geom.bar)
draw(SVG("kaggle_barplot.svg"),barplot)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment