Skip to content

Instantly share code, notes, and snippets.

@vnegi10
Last active July 26, 2020 13:24
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 vnegi10/25b5ee7a75d1a366456c8c369b5210e7 to your computer and use it in GitHub Desktop.
Save vnegi10/25b5ee7a75d1a366456c8c369b5210e7 to your computer and use it in GitHub Desktop.
############################# Calculate number of daily reported cases ####################################
y_tmp = deepcopy(y); # creates an independent copy, changes in y_tmp won't affect y
rows,cols = size(y_tmp)
dfrows = nrow(y_tmp);
name = names(y_tmp);
y_daily = similar(y_tmp,dfrows-1); # copy the structure to an empty dataframe with dfrows-1 rows
for j = 1:length(name)
for i = 1:dfrows-1
y_daily[!,name[j]][i] = y_tmp[!,name[j]][i+1] - y_tmp[!,name[j]][i] # calculate number of daily increase in reported cases by subtracting numbers of previous day
end
end
x_daily = deepcopy(x);
popfirst!(x_daily); # remove first entry, daily increase can only be reported from the next date
gr(size=(900,600))
display(@df y_daily bar(x_daily, cols(1:cols),
label = reshape(names(y),(1,length(names(y)))),
xlabel = "Time",
ylabel = "Daily number of reported cases",
xticks = x[1:7:end],
xrotation = 45,
legend = :topleft,
grid = false,
framestyle = :semi,
legendfontsize = 9,
formatter = :plain))
savefig("Daily_cases.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment