Skip to content

Instantly share code, notes, and snippets.

@vnegi10
Last active August 15, 2020 21:50
Show Gist options
  • Save vnegi10/b39c4a6db249ad5177590fbd23a87a0d to your computer and use it in GitHub Desktop.
Save vnegi10/b39c4a6db249ad5177590fbd23a87a0d to your computer and use it in GitHub Desktop.
Top_five_anim = @animate for i in 50:length(names(data_df)) # loop through dates
sort!(data_df, :($i), rev = true) # sort original DataFrame in descending order based on values in last column (latest date)
countries_sort = data_df[1:5,Symbol("Country/Region")] # list of top 5 countries
latest_reported_cases = data_df[1:5,i] # number of reported cases in top 5 countries
labels = string.(latest_reported_cases)
gr(size=(800,500))
bar(countries_sort, latest_reported_cases,
ylabel = "Total number of confirmed cases",
xlabel = "Countries",
legend = false,
color = collect(1:length(countries_sort)),
title = names(data_df)[i],
bar_width = 0.50,
linecolor = :match,
grid = true,
framestyle = :box,
formatter = :plain,
fillalpha = 0.75
)
ylims!(0,1.25*maximum(data_df[!,length(names(data_df))])) # set a constant y-scale based on the maximum value
end
gif(Top_five_anim, "Top_five_anim.gif", fps = 2) # output filename and frame rate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment