Created
October 30, 2022 14:51
-
-
Save AnupJoseph/e88148585adbef30f7ab992e8caa768b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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