In this notebook, we use Plots.jl and Pluto.jl to visualise the Covid-19 confirmed cases across the world.
The notebook below shows you how to generate the animated plot.Note: This is the HTML rendered output of the notebook so it looses all the interactivity. You may want to directly load the pluto notebook in Julia.
GitHub RepositoryCovid-19 Confirmed Cases
xxxxxxxxxx
md"# Covid-19 Confirmed Cases"
xxxxxxxxxx
begin
using Pkg
Pkg.activate(".")
Pkg.add(["CSV","DataFrames", "PlutoUI"])
using CSV
using DataFrames
using PlutoUI
using Plots
using Dates
end
Data
Download the data from Johns Hopkins University Center for Systems Science and Engineering
xxxxxxxxxx
md"# Data
Download the data from Johns Hopkins University Center for Systems Science and Engineering"
"covid_data.csv"
xxxxxxxxxx
begin
url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv";
download(url, "covid_data.csv");
end
Load data into dataframe
xxxxxxxxxx
266 rows × 252 columns (omitted printing of 246 columns)
Province/State | Country/Region | Lat | Long | 1/22/20 | 1/23/20 | |
---|---|---|---|---|---|---|
String? | String | Float64 | Float64 | Int64 | Int64 | |
1 | missing | Afghanistan | 33.9391 | 67.71 | 0 | 0 |
2 | missing | Albania | 41.1533 | 20.1683 | 0 | 0 |
3 | missing | Algeria | 28.0339 | 1.6596 | 0 | 0 |
4 | missing | Andorra | 42.5063 | 1.5218 | 0 | 0 |
5 | missing | Angola | -11.2027 | 17.8739 | 0 | 0 |
6 | missing | Antigua and Barbuda | 17.0608 | -61.7964 | 0 | 0 |
7 | missing | Argentina | -38.4161 | -63.6167 | 0 | 0 |
8 | missing | Armenia | 40.0691 | 45.0382 | 0 | 0 |
9 | Australian Capital Territory | Australia | -35.4735 | 149.012 | 0 | 0 |
10 | New South Wales | Australia | -33.8688 | 151.209 | 0 | 0 |
11 | Northern Territory | Australia | -12.4634 | 130.846 | 0 | 0 |
12 | Queensland | Australia | -27.4698 | 153.025 | 0 | 0 |
13 | South Australia | Australia | -34.9285 | 138.601 | 0 | 0 |
14 | Tasmania | Australia | -42.8821 | 147.327 | 0 | 0 |
15 | Victoria | Australia | -37.8136 | 144.963 | 0 | 0 |
16 | Western Australia | Australia | -31.9505 | 115.861 | 0 | 0 |
17 | missing | Austria | 47.5162 | 14.5501 | 0 | 0 |
18 | missing | Azerbaijan | 40.1431 | 47.5769 | 0 | 0 |
⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
xxxxxxxxxx
begin
csv_data = CSV.File("covid_data.csv")
data = DataFrame(csv_data)
end
Rename the columns
xxxxxxxxxx
6 rows × 252 columns (omitted printing of 244 columns)
province | country | latitude | longitude | 1/22/20 | 1/23/20 | 1/24/20 | 1/25/20 | |
---|---|---|---|---|---|---|---|---|
String? | String | Float64 | Float64 | Int64 | Int64 | Int64 | Int64 | |
1 | missing | Afghanistan | 33.9391 | 67.71 | 0 | 0 | 0 | 0 |
2 | missing | Albania | 41.1533 | 20.1683 | 0 | 0 | 0 | 0 |
3 | missing | Algeria | 28.0339 | 1.6596 | 0 | 0 | 0 | 0 |
4 | missing | Andorra | 42.5063 | 1.5218 | 0 | 0 | 0 | 0 |
5 | missing | Angola | -11.2027 | 17.8739 | 0 | 0 | 0 | 0 |
6 | missing | Antigua and Barbuda | 17.0608 | -61.7964 | 0 | 0 | 0 | 0 |
xxxxxxxxxx
begin
rename!(data, 1 => "province", 2 => "country", 3 => "latitude", 4 => "longitude")
head(data)
end
Extract the list of unique countries
x
md"
Extract the list of unique countries
"
"Afghanistan"
"Albania"
"Algeria"
"Andorra"
"Angola"
"Antigua and Barbuda"
"Argentina"
"Armenia"
"Australia"
"Australia"
"Australia"
"Australia"
"Australia"
"Australia"
"Australia"
"Australia"
"Austria"
"Azerbaijan"
"Bahamas"
"Bahrain"
"Bangladesh"
"Barbados"
"Belarus"
"Belgium"
"Belize"
"Benin"
"Bhutan"
"Bolivia"
"Bosnia and Herzegovina"
"Botswana"
"Brazil"
"Brunei"
"Bulgaria"
"Burkina Faso"
"Burma"
"Burundi"
"Cabo Verde"
"Cambodia"
"Cameroon"
"Canada"
"United Kingdom"
"Uruguay"
"Uzbekistan"
"Venezuela"
"Vietnam"
"West Bank and Gaza"
"Western Sahara"
"Yemen"
"Zambia"
"Zimbabwe"
x
all_countries = data[:, :country]
"Afghanistan"
"Albania"
"Algeria"
"Andorra"
"Angola"
"Antigua and Barbuda"
"Argentina"
"Armenia"
"Australia"
"Austria"
"Azerbaijan"
"Bahamas"
"Bahrain"
"Bangladesh"
"Barbados"
"Belarus"
"Belgium"
"Belize"
"Benin"
"Bhutan"
"Bolivia"
"Bosnia and Herzegovina"
"Botswana"
"Brazil"
"Brunei"
"Bulgaria"
"Burkina Faso"
"Burma"
"Burundi"
"Cabo Verde"
"Cambodia"
"Cameroon"
"Canada"
"Central African Republic"
"Chad"
"Chile"
"China"
"Colombia"
"Comoros"
"Congo (Brazzaville)"
"United Kingdom"
"Uruguay"
"Uzbekistan"
"Venezuela"
"Vietnam"
"West Bank and Gaza"
"Western Sahara"
"Yemen"
"Zambia"
"Zimbabwe"
xxxxxxxxxx
countries = unique(all_countries)
"Afghanistan"
"Albania"
"Algeria"
"Andorra"
"Angola"
"Antigua and Barbuda"
"Argentina"
"Armenia"
"Australia"
"Australia"
"Australia"
"Australia"
"Australia"
"Australia"
"Australia"
"Australia"
"Austria"
"Azerbaijan"
"Bahamas"
"Bahrain"
"Bangladesh"
"Barbados"
"Belarus"
"Belgium"
"Belize"
"Benin"
"Bhutan"
"Bolivia"
"Bosnia and Herzegovina"
"Botswana"
"Brazil"
"Brunei"
"Bulgaria"
"Burkina Faso"
"Burma"
"Burundi"
"Cabo Verde"
"Cambodia"
"Cameroon"
"Canada"
"United Kingdom"
"Uruguay"
"Uzbekistan"
"Venezuela"
"Vietnam"
"West Bank and Gaza"
"Western Sahara"
"Yemen"
"Zambia"
"Zimbabwe"
x
data[:, :country]
Enter cell code...
xxxxxxxxxx
Enter cell code...
xxxxxxxxxx
Enter cell code...
xxxxxxxxxx
11 rows × 252 columns (omitted printing of 245 columns)
province | country | latitude | longitude | 1/22/20 | 1/23/20 | 1/24/20 | |
---|---|---|---|---|---|---|---|
String? | String | Float64 | Float64 | Int64 | Int64 | Int64 | |
1 | Anguilla | United Kingdom | 18.2206 | -63.0686 | 0 | 0 | 0 |
2 | Bermuda | United Kingdom | 32.3078 | -64.7505 | 0 | 0 | 0 |
3 | British Virgin Islands | United Kingdom | 18.4207 | -64.64 | 0 | 0 | 0 |
4 | Cayman Islands | United Kingdom | 19.3133 | -81.2546 | 0 | 0 | 0 |
5 | Channel Islands | United Kingdom | 49.3723 | -2.3644 | 0 | 0 | 0 |
6 | Falkland Islands (Malvinas) | United Kingdom | -51.7963 | -59.5236 | 0 | 0 | 0 |
7 | Gibraltar | United Kingdom | 36.1408 | -5.3536 | 0 | 0 | 0 |
8 | Isle of Man | United Kingdom | 54.2361 | -4.5481 | 0 | 0 | 0 |
9 | Montserrat | United Kingdom | 16.7425 | -62.1874 | 0 | 0 | 0 |
10 | Turks and Caicos Islands | United Kingdom | 21.694 | -71.7979 | 0 | 0 | 0 |
11 | missing | United Kingdom | 55.3781 | -3.436 | 0 | 0 | 0 |
xxxxxxxxxx
filter(x -> x.country == "United Kingdom", data)
243
xxxxxxxxxx
US_row = findfirst(==("US"), all_countries)
DataFrameRow (252 columns)
province | country | latitude | longitude | 1/22/20 | 1/23/20 | 1/24/20 | 1/25/20 | 1/26/20 | 1/27/20 | |
---|---|---|---|---|---|---|---|---|---|---|
String? | String | Float64 | Float64 | Int64 | Int64 | Int64 | Int64 | Int64 | Int64 | |
243 | missing | US | 40.0 | -100.0 | 1 | 1 | 2 | 2 | 5 | 5 |
xxxxxxxxxx
data[US_row, :]
Plots
xxxxxxxxxx
We can now start to plot the data for each country
xxxxxxxxxx
md"
We can now start to plot the data for each country
"
xxxxxxxxxx
country Select(countries)
1
x
current_country_idx = findfirst(x -> x == country, all_countries)
scatter(Vector(data[current_country_idx, 5:end]), m=:o, alpha=0.5, ms=3, xlabel="Day", ylabel="Cumulative cases", leg=false, title="Covid-19 Confirmed Cases - $(country)")
"province"
"country"
"latitude"
"longitude"
"1/22/20"
"1/23/20"
"1/24/20"
"1/25/20"
"1/26/20"
"1/27/20"
"1/28/20"
"1/29/20"
"1/30/20"
"1/31/20"
"2/1/20"
"2/2/20"
"2/3/20"
"2/4/20"
"2/5/20"
"2/6/20"
"2/7/20"
"2/8/20"
"2/9/20"
"2/10/20"
"2/11/20"
"2/12/20"
"2/13/20"
"2/14/20"
"2/15/20"
"2/16/20"
"2/17/20"
"2/18/20"
"2/19/20"
"2/20/20"
"2/21/20"
"2/22/20"
"2/23/20"
"2/24/20"
"2/25/20"
"2/26/20"
"9/16/20"
"9/17/20"
"9/18/20"
"9/19/20"
"9/20/20"
"9/21/20"
"9/22/20"
"9/23/20"
"9/24/20"
"9/25/20"
column_names = names(data)
Daily Cumulative Cases
Next, we generate the timer based plot for selected countries
xxxxxxxxxx
md"## Daily Cumulative Cases
Next, we generate the timer based plot for selected countries
"
2020-01-22
2020-01-23
2020-01-24
2020-01-25
2020-01-26
2020-01-27
2020-01-28
2020-01-29
2020-01-30
2020-01-31
2020-02-01
2020-02-02
2020-02-03
2020-02-04
2020-02-05
2020-02-06
2020-02-07
2020-02-08
2020-02-09
2020-02-10
2020-02-11
2020-02-12
2020-02-13
2020-02-14
2020-02-15
2020-02-16
2020-02-17
2020-02-18
2020-02-19
2020-02-20
2020-02-21
2020-02-22
2020-02-23
2020-02-24
2020-02-25
2020-02-26
2020-02-27
2020-02-28
2020-02-29
2020-03-01
2020-09-16
2020-09-17
2020-09-18
2020-09-19
2020-09-20
2020-09-21
2020-09-22
2020-09-23
2020-09-24
2020-09-25
xxxxxxxxxx
# We will need to convert the date from string to date format
begin
date_strings = String.(names(data)[5:end])
date_format = Dates.DateFormat("m/d/Y")
parse(Date, date_strings[1], date_format)
dates = parse.(Date, date_strings, date_format) .+ Year(2000)
end
6 rows × 252 columns (omitted printing of 242 columns)
province | country | latitude | longitude | 1/22/20 | 1/23/20 | 1/24/20 | 1/25/20 | 1/26/20 | 1/27/20 | |
---|---|---|---|---|---|---|---|---|---|---|
String? | String | Float64 | Float64 | Int64 | Int64 | Int64 | Int64 | Int64 | Int64 | |
1 | Brazil | Brazil | -14.235 | -51.9253 | 0 | 0 | 0 | 0 | 0 | 0 |
2 | India | India | 20.5937 | 78.9629 | 0 | 0 | 0 | 0 | 0 | 0 |
3 | Italy | Italy | 41.8719 | 12.5674 | 0 | 0 | 0 | 0 | 0 | 0 |
4 | Mexico | Mexico | 23.6345 | -102.553 | 0 | 0 | 0 | 0 | 0 | 0 |
5 | Spain | Spain | 40.4637 | -3.74922 | 0 | 0 | 0 | 0 | 0 | 0 |
6 | US | US | 40.0 | -100.0 | 1 | 1 | 2 | 2 | 5 | 5 |
begin
filter_countries = ["US","India", "Brazil", "Italy", "Spain", "Mexico"]
certain_countries = filter(x -> x.country in filter_countries , data)
end
Add the Clock to animate the plot
xxxxxxxxxx
md"
Add the Clock to animate the plot
"
xxxxxxxxxx
today Clock(0.3)
Date: 2020-02-12
data source: Johns Hopkins CSSE
xxxxxxxxxx
plot_country (generic function with 1 method)
xxxxxxxxxx
function plot_country(name, row)
df = Vector(data[row, 5:today])
plot!(df, m=:o, alpha=0.5, ms=2, xlabel="Day", ylabel="Cumulative cases", label=name)
end
certain_countries_plot = begin
plot(xlabel="day", ylabel="cumulative cases",size=(680,500), leg=:topleft)
for country in filter_countries
current_country = findfirst(x -> x == country, all_countries)
plot_country(country, current_country)
end
title!("Confirmed cases of Covid-19 Confirmed of $(dates[today])")
end
And, that's it folks
xxxxxxxxxx
md"
And, that's it folks
"